Script bash per cambiare lo stato di Zoneminder

Script per cambiare lo stato di Zoneminder con il crontab e per verificare ad ogni avvio che sia impostato lo stato corretto.

zoneminder_state.sh:

#!/bin/bash
zmdbuser=`cat /etc/zm/zm.conf | grep ZM_DB_USER | awk -F= '{print $2}' | tr -d ' '`
zmdbpass=`cat /etc/zm/zm.conf | grep ZM_DB_PASS | awk -F= '{print $2}' | tr -d ' '`
runstate=`mysql -N -B -u$zmdbuser -p$zmdbpass zm -e "select Name  from States where isActive=1 LIMIT 1;"`

alarmedstate='Armed'

#echo $runstate # for debug only


function state {

if [ "$runstate" != "$alarmedstate" ]; then
        /usr/bin/zmpkg.pl ${1}
else
        exit
fi

}


function boot {

hour=$(date +%H)

daystate='Day'
nightstate='Night'
hour_day_start='8'
hour_day_end='24'

if [ "$runstate" == "$alarmedstate" ]; then
	exit
elif (( $hour_day_start <= 10#$hour && 10#$hour < $hour_day_end )); then
	if [ "$runstate" != "$daystate" ]; then
		/usr/bin/zmpkg.pl $daystate
	else
		exit
	fi
elif (( $hour_day_end <= 10#$hour && 10#$hour < $hour_day_start )); then
	if [ "$runstate" != "$nightstate" ]; then
                /usr/bin/zmpkg.pl $nightstate
        else
                exit
        fi
else
	echo there is a problem with Zoneminder
fi

}

[email protected]


In crontab possiamo impostarlo in questo modo:

0 8 * * * /opt/zoneminder_state.sh state Day
0 0 * * * /opt/zoneminder_state.sh state Night
@reboot sleep 180; /opt/zoneminder_state.sh boot

 

Section: 

Commenti

Aggiungi un commento