Page 1 of 1

Cleaning Up Events

Posted: Fri Mar 16, 2007 4:43 pm
by tarantir
Hello all,
I have motion detection running on my cameras and occasionally as the day passes shadows create events which trigger video capture. I have created a script, which is run by CRON, which deletes Events based on the length of the video. I have this running on a Fedora 5 system.

Simply create the following files and change the parameters in conf.php to match your database. Secure the files as needed, also thresholdes for your environment will differ.

EventsClean.php

Code: Select all

<?
// includes
include("/var/www/sql/conf.php");

// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// Clean Frames Table
$query = "Delete Frames.* from Frames, Events where Events.Id = Frames.EventId and Events.Length <= '0.50';";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
printf("Records deleted from Frames: %d\n", mysql_affected_rows());

// Clean Stats Table
$query = "Delete Stats.* from Stats, Events where Events.Id = Stats.EventId and Events.Length <= '0.50';";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
printf("Records deleted from Stats: %d\n", mysql_affected_rows());

// Clean Events Table
$query = "Delete from Events where Events.Length <= '0.50';";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
printf("Records deleted from Events: %d\n", mysql_affected_rows());

// close connection
mysql_close($connection);
?>
conf.php

Code: Select all

<?
// database configuration
$host = "";
$user = "";
$pass = "";
$db = "";
?>
CRON Job run command
“php /var/www/sql/EventsClean.php >/dev/null 2>&1”