Script - Better than PurgeWhenFull

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
tburt11
Posts: 11
Joined: Sat Jun 16, 2007 4:20 pm

Script - Better than PurgeWhenFull

Post by tburt11 » Sat Jun 16, 2007 4:35 pm

I am running an older version of ZM, but I wanted to post this into the current release, as I believe it may be usefull still.

I have seven cameras, and the problem with PurgeWhenFull is that it does not pick the image directory that is fullest. When they fill up to 32K files, the images stop recording.

Deleting the images is only part of the problem, as there are still entries in the database which need to be purged as well.

I wrote these crummy scripts (I was lazy) and they do the job wonderfully. I wanted to share them.

The script also preserves your archived images.

Here is my crontab entry:

0 10 * * * /usr/local/bin/zmclean 1 > /dev/null 2>&1
1 10 * * * /usr/local/bin/zmclean 4 > /dev/null 2>&1
2 10 * * * /usr/local/bin/zmclean 7 > /dev/null 2>&1
3 10 * * * /usr/local/bin/zmclean 8 > /dev/null 2>&1
4 10 * * * /usr/local/bin/zmclean 9 > /dev/null 2>&1
5 10 * * * /usr/local/bin/zmclean 11 > /dev/null 2>&1
6 10 * * * /usr/local/bin/zmclean 12 > /dev/null 2>&1

zmclean:

#!/bin/bash

if [ x$1 == x ]
then
echo "missing param"
exit 1
fi

folder="/var/www/html/events/$1"

cd $folder

p=`/bin/pwd`

if [ x$p != x/var/www/html/events/$1 ]
then
echo "wrong folder"
exit 1
fi

/usr/bin/find . -type d -mtime +30 -exec /usr/local/bin/zmzap {} \;

and
zmzap:


#!/bin/bash

if [ x$1 == x ]
then
echo "missing param"
exit 1
fi

echo $1 | grep './'
if [ $? == 0 ]
then
targ=`echo $1 | /bin/cut -c 3-`
else
targ=$1
fi

if [ ! -d $targ ]
then
echo "missing target dir"
exit 1
fi


x=`/usr/bin/mysql -uzm -pzm << YYYY
use zm;
select Archived from Events where id = $targ;
quit
YYYY
`
y=`echo $x | /bin/cut -c 10`

if [ $y == 1 ]
then
echo "archived"
exit 0
fi

echo $targ
/bin/rm -rf $targ

/usr/bin/mysql -uzm -pzm << XXXX
use zm;
delete from Events where id = $targ;
delete from Frames where EventId = $targ;
quit
XXXX

grimsy
Posts: 3
Joined: Mon Jul 02, 2007 4:09 am

Post by grimsy » Mon Jul 02, 2007 4:12 am

thanks for posting that. Works a charm.

ynn
Posts: 149
Joined: Fri Mar 17, 2006 2:30 am

Post by ynn » Mon Mar 17, 2008 3:27 am

I tried this script just now, and got this error messages

/usr/local/bin/zmzap: line 32: [: ==: unary operator expected 492869
ERROR 1045 (28000): Access denied using 'zm'@'localhost' (using password: YES

did i did wrong configuration?

timcraig
Posts: 195
Joined: Mon Dec 10, 2007 5:53 pm
Location: San Jose, CA
Contact:

Post by timcraig » Mon Mar 17, 2008 6:36 am

ynn wrote:I tried this script just now, and got this error messages

/usr/local/bin/zmzap: line 32: [: ==: unary operator expected 492869
ERROR 1045 (28000): Access denied using 'zm'@'localhost' (using password: YES

did i did wrong configuration?
You have a different Mysql username or password then what the script uses.

In the line:
x=`/usr/bin/mysql -uzm -pzm << YYYY

replace "-uzm" to "-u<your mysql username> and "-pzm" to "-p<your mysql password>"

ynn
Posts: 149
Joined: Fri Mar 17, 2006 2:30 am

Post by ynn » Mon Mar 17, 2008 1:33 pm

Thanks for quick reply, how many events will it be deleted by this script? like in Purgewhenfull we can set it like 300 events only when it reach 80% of disk capacity.

thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests