New autoclean script for events
Posted: Mon Jan 26, 2004 12:45 pm
hi again...
these weekend i've made a script that check if the disk is full, and , if that is true, it removes all the oldest events from all monitors...
i have checked it, and it worked ok... its simple to configure it, and you should run it via cron
... its below ...
#----- cut here
## Script made By victor diago to the brilliant - Zone Minder system
#!/bin/bash
### You should pass a directory to autoclean, like autoclean.sh /var/www/htdocs/events
cd $1
## assigns the free space in mbs to a variable
espaco=`df -m|cut -c 42-50|tail -1|sed s/" "/""/g`
## Check if the free space is less than 100 MB
if [ "$espaco" -lt 100 ];
then
## this assign the oldest day to a variable
tempodelete=0
diretorio=`ls|head -1`
cd "$diretorio"
tempodelete=`ls -c --full-time -t -G|cut -c 35-44|grep 20|tail -1`
cd ..
# This loop delete any files (directories in this case) which time (DAY ONLY)
# match with the oldest day detected before. Every time you delete an event, zmaudit run. this ensure that
# You will not see many broken links in the web interface.
for x in *;
do
cd "$x";
ls -l -c --full-time|grep "$tempodelete"|cut -c 80- > /tmp/deletar;
for x in `cat /tmp/deletar`;
do
rm -rf $x;
zmaudit.pl -y;
done;
cd ..;
done;
rm -rf /tmp/deletar
--- Cut here
these weekend i've made a script that check if the disk is full, and , if that is true, it removes all the oldest events from all monitors...
i have checked it, and it worked ok... its simple to configure it, and you should run it via cron
... its below ...
#----- cut here
## Script made By victor diago to the brilliant - Zone Minder system
#!/bin/bash
### You should pass a directory to autoclean, like autoclean.sh /var/www/htdocs/events
cd $1
## assigns the free space in mbs to a variable
espaco=`df -m|cut -c 42-50|tail -1|sed s/" "/""/g`
## Check if the free space is less than 100 MB
if [ "$espaco" -lt 100 ];
then
## this assign the oldest day to a variable
tempodelete=0
diretorio=`ls|head -1`
cd "$diretorio"
tempodelete=`ls -c --full-time -t -G|cut -c 35-44|grep 20|tail -1`
cd ..
# This loop delete any files (directories in this case) which time (DAY ONLY)
# match with the oldest day detected before. Every time you delete an event, zmaudit run. this ensure that
# You will not see many broken links in the web interface.
for x in *;
do
cd "$x";
ls -l -c --full-time|grep "$tempodelete"|cut -c 80- > /tmp/deletar;
for x in `cat /tmp/deletar`;
do
rm -rf $x;
zmaudit.pl -y;
done;
cd ..;
done;
rm -rf /tmp/deletar
--- Cut here