#!/bin/bash

# Copyright (C) 2005-2007 Silvian Cretu <silvian86@yahoo.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 

# Constante:
partitie=/var/www # partitia monitorizata
procentMaxim="97%" # procentul maxim de ocupare acceptat pt partitia monitorizata
X=1 # se vor sterge directoarele mai vechi de X zile
director=/var/www/html/camera/events/2 # directorul din care se vor sterge subdirectoarele

# Cat de ocupata este partitia monitorizata (in procente):
procentOcupare=$(df -h | grep $partitie | awk '{print $5}')
 
if [[ "$procentMaxim" < "$procentOcupare" ]] || [ "$procentOcupare" == "100%" ];
	then # trebuie sterse directoarele mai vechi de X zile
		find $director -type d -mtime +$X -exec rm -rf {} \;
fi
 
exit

