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
# License: GPL
#
# Author: Mentor <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
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

}

$@


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