Change Zones with State change

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
Flav
Posts: 38
Joined: Tue Jan 12, 2010 2:26 pm

Change Zones with State change

Post by Flav »

I need change zones for the night state but it is impossible in ZM i'v juste add a cron job for change state and modifi zones

here for change state http://www.zoneminder.com/forums/viewtopic.php?t=15321

But somme changes

After compile c program


2) Find your location (GPS or in google maps/earth)
3) Create script like this

Code: Select all

#! /bin/bash 
# /root/timeup  
# Author: fvillant 
# Date: 2007.10.10.
# Recuperation du lever et du coucher du Soleil a Porto-Vecchio pour la date du lendemain

/root/sunrise `date -d "+1 day" "+%Y %m %d"` 41.41 -9.22
4)Edit /etc/crontab and fix line where you enter the command line you nerver add something before !!!!!!!!!!!!!!
4.1) At the end ad the commande line 30 23 * * * root /root/editcron

5) Create a script /root/editcron

Code: Select all

#!/usr/bin/perl -w
#
# 28 Janvier 2010 Creation Flavien Villant
# Edition crontab pour modification sunset
# sunrise selon le jour et l'heure la la
# 
#
#
#
system("/root/timeup > sun.txt");
open(FILE,"sun.txt");
@arr = <FILE>;
for $line (@arr) {
chomp $line;
# Recuperation des horaires
$sunriseH=substr($line,21,2);
$sunriseM=substr($line,24,2);
$sunsetH=substr($line,51,2);
$sunsetM=substr($line,54,2);



$sunsetrise = "# Mode Jour/Nuit Zoneminder ".$Line." NE PAS DECOMMENTER";
$jour = $sunriseM." ".$sunriseH." * * * root /root/zmday";
$nuit = $sunsetM." ".$sunsetH." * * * root /zmnight";

}

close(FILE);




open(FILE,"/etc/crontab");
my @crn = <FILE>;
close(FILE);

$crn[23] = $sunsetrise;
$crn[24] = $jour;
$crn[25] = $nuit;

open(FILE, ">/etc/crontab") || die "Erreur E/S:$!\n";
foreach my $ligne (@crn) {
    chomp $ligne;
    print FILE "$ligne\n";
}


system("chmod 754 /etc/crontab");
system("chmod +x /etc/crontab");

exit;
In my crontag the line with the script are the 24 and 25 but in pearl the first line is the 0
BEWARE NEVER AD LINE BEFORE THIS

Creat two files
/root/zmday

zmday code :

Code: Select all

#!/usr/bin/perl -w
#
# 20 Fevrier 2010 Creation Flavien Villant
# 
#
#
#

# databse connection info ...
$username = "zmuser";
$password = "zmpass";
$database = "zm";
# @host = ("localhost");

# Insertion SQL Zones de Jour
system("mysql --user=".$username." --password=".$password." ".$database." < /root/ZonesDay.sql");
# Lancement ZM Mode State Jour
system("/usr/bin/zmpkg.pl Day");
exit;

zmnight code :

Code: Select all

#!/usr/bin/perl -w
#
# 20 Fevrier 2010 Creation Flavien Villant
# 
#
#
#

# databse connection info ...
$username = "zmuser";
$password = "zmpass";
$database = "zm";
# @host = ("localhost");

# Insertion SQL Zones de Nuit
system("mysql --user=".$username." --password=".$password." ".$database." < /root/ZonesNight.sql");
# Lancement ZM Mode State Nuit
system("/usr/bin/zmpkg.pl Night");
exit;
The ZonesNight.sql and ZonesDay.sql in this scripts are two SQL export of the zone table, one for the day and one for the night.
Post Reply