New autoclean script for events

Support and queries relating to all previous versions of ZoneMinder
Locked
User avatar
victor_diago
Posts: 245
Joined: Wed Jan 21, 2004 2:44 pm
Location: Brazil, sao paulo
Contact:

New autoclean script for events

Post by victor_diago »

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
User avatar
rdmelin
Posts: 863
Joined: Wed Oct 29, 2003 2:23 pm
Location: Ellensburg, WA USA

Re: New autoclean script for events

Post by rdmelin »

Hi victor, and all,
This is a useful contribution. However be careful about deploying without testing. On my laptop the line:
espaco=`df -m|cut -c 42-50|tail -1|sed s/" "/""/g`
returns the free space on my windows partition. So some customization will be needed for some partitioning schemes.
But its a fine template to start from.

Best regards,

Ross
User avatar
victor_diago
Posts: 245
Joined: Wed Jan 21, 2004 2:44 pm
Location: Brazil, sao paulo
Contact:

Re: New autoclean script for events

Post by victor_diago »

thanks ross...


sorry about the line, i am changing all the script, to release a new improved version...

when its done i will past it here ok ?

thanks again..


victor diago
mapasainformatica
Posts: 15
Joined: Wed Mar 17, 2004 7:49 am
Location: Italy

Post by mapasainformatica »

df -m /dev/hda2 |cut -c 42-50|tail -1|sed s/" "/""/g

with /dev/hda2 is partition when save the events
Locked