Ciao Bli,
si infatti
il skript e ben lungo....pero se vedi il screenshoot si capisce meglio
vorrei...almeno compe ho provato ad impostare...che se un reader va in OUT / OFFLinE...il Router (che sarrebbe il mio FRitzbox-server)...fa un restart...fino che tutti Reader sono di nuovo OK....
#!/bin/sh
# ZebraDem.com - Freetz Watchdog Addon
. /etc/init.d/modlibrc
. /mod/etc/conf/watchdog.cfg
DAEMON=watchdog
DAEMON_LONG_NAME='ZebraDem/NFR Watchdog'
get_status() {
if [ "$WATCHDOG_CHECK_CARDINIT" = "yes" -o "$WATCHDOG_CHECK_CAMRUN" = "yes" -o "$WATCHDOG_CHECK_BULKWRITE" = "yes" -o "$WATCHDOG_CHECK_DYNDNS" = "yes" ]; then
if [ -n "$(pidof crond)" ]; then
if [ -n "$(crontab -l 2>/dev/null | grep $DAEMON)" ]; then
return 0
else
return 3
fi
else
return 3
fi
elif [ ! -e /tmp/flash/mod/rc.custom ]; then
return 3
elif [ -n "$(grep $DAEMON /tmp/flash/mod/rc.custom)" ]; then
return 0
else
return 3
fi
}
get_ustor() {
USTOR_PATH=''
if [ -d /data/watchdog ]; then USTOR_PATH="/data"
elif [ -d /cs/watchdog ]; then USTOR_PATH="/cs"
else
for i in 1 2; do
local USTOR_PATHS="$(mount | grep '/var/media/ftp/' | cut -d ' ' -f3)"
for USTOR in $USTOR_PATHS; do
if [ -n "$(ls "$USTOR")" ]; then
USTOR_PATH="$USTOR"
break
fi
done
if [ $i -eq 1 ]; then
if [ -z "$USTOR_PATH" ]; then sleep 20; else break; fi
else
if [ -z "$USTOR_PATH" ]; then USTOR_PATH="/var/media/ftp/uStor01"; fi
fi
done
fi
WORKING_DIR=${WATCHDOG_LOG_PATH/%uStor%/$USTOR_PATH}
}
cleanup() {
if [ -e /tmp/flash/mod/rc.custom ]; then
if cat /tmp/flash/mod/rc.custom|grep 'watchdog' >/dev/null; then
sed '/watchdog/d' /tmp/flash/mod/rc.custom >/var/tmp/rc.custom.txt
cat /var/tmp/rc.custom.txt >/tmp/flash/mod/rc.custom
rm /var/tmp/rc.custom.txt
modsave flash >/dev/null
fi
fi
if [ -n "$(pidof crond)" ]; then
local RESTART_CROND='y'
killall crond
else
local RESTART_CROND='n'
cp /tmp/flash/mod/crontab /var/spool/cron/crontabs/root
fi
if [ -n "$(crontab -l 2>/dev/null | grep $DAEMON)" ]; then
cat /tmp/flash/mod/crontab | grep -v $DAEMON >/tmp/flash/mod/crontab
cp /tmp/flash/mod/crontab /var/spool/cron/crontabs/root
if [ -n "$(crontab -l 2>/dev/null)" ]; then
if [ "$RESTART_CROND" = "y" ]; then
if [ -z "$(pidof crond)" ]; then crond -b; fi
fi
fi
fi
}
start() {
get_status
case $? in
0)
echo "Starting ${DAEMON_LONG_NAME} ... already running."
;;
3)
echo -n "Starting ${DAEMON_LONG_NAME} ... "
cleanup
if [ -e /tmp/flash/mod/rc.custom ]; then
echo "# BEGIN: $DAEMON" >>/tmp/flash/mod/rc.custom
else
echo "# BEGIN: $DAEMON" >/tmp/flash/mod/rc.custom
fi
echo "/etc/init.d/rc.$DAEMON c_rb" >>/tmp/flash/mod/rc.custom
echo "# END: $DAEMON" >>/tmp/flash/mod/rc.custom
modsave flash >/dev/null
if [ "$WATCHDOG_CHECK_CARDINIT" = "yes" -o "$WATCHDOG_CHECK_CAMRUN" = "yes" -o "$WATCHDOG_CHECK_BULKWRITE" = "yes" -o "$WATCHDOG_CHECK_DYNDNS" = "yes" ]; then
if [ -n "$(pidof crond)" ]; then killall crond; fi
if [ -e /tmp/flash/mod/crontab ]; then
echo "# BEGIN: $DAEMON" >>/tmp/flash/mod/crontab
else
echo "# BEGIN: $DAEMON" >/tmp/flash/mod/crontab
fi
if [ "$WATCHDOG_CHECK_CARDINIT" = "yes" ]; then
echo "*/$WATCHDOG_CHECKING_INTERVAL * * * * /etc/init.d/rc.$DAEMON c_ie" >>/tmp/flash/mod/crontab
fi
if [ "$WATCHDOG_CHECK_CAMRUN" = "yes" ]; then
echo "*/$WATCHDOG_CHECKING_INTERVAL * * * * /etc/init.d/rc.$DAEMON c_cr" >>/tmp/flash/mod/crontab
fi
if [ "$WATCHDOG_CHECK_BULKWRITE" = "yes" ]; then
echo "*/$WATCHDOG_CHECKING_INTERVAL * * * * /etc/init.d/rc.$DAEMON c_bw" >>/tmp/flash/mod/crontab
fi
if [ "$WATCHDOG_CHECK_DYNDNS" = "yes" ]; then
echo "*/$WATCHDOG_CHECKING_INTERVAL * * * * /etc/init.d/rc.$DAEMON c_dd" >>/tmp/flash/mod/crontab
fi
echo "# END: $DAEMON" >>/tmp/flash/mod/crontab
cp /tmp/flash/mod/crontab /var/spool/cron/crontabs/root
if [ -z "$(pidof crond)" ]; then crond -b; fi
fi
get_status
case $? in
0)
echo 'done.'
;;
3)
echo 'failed.'
;;
esac
;;
esac
}
stop() {
get_status
case $? in
0)
echo -n "Stopping ${DAEMON_LONG_NAME} ... "
cleanup
echo 'done.'
;;
3)
echo "Stopping ${DAEMON_LONG_NAME} ... not running."
;;
esac
}
transmit_mail() {
mailer -s "$DAEMON_LONG_NAME - $ERROR_MSG" -f $WATCHDOG_MAIL_FROM -t $WATCHDOG_MAIL_TO -m $WATCHDOG_MAIL_SERVER -a $WATCHDOG_MAIL_USER -w $WATCHDOG_MAIL_PASSWORD
echo "$(date) => transmitted mail to $WATCHDOG_MAIL_TO" >>$WORKING_DIR/$DAEMON.log
}
check_camrunning() {
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_CAMD3" = "yes" ]; then
if [ "$(/etc/init.d/rc.camd3 status)" = "stopped" ]; then
local ERROR_CAM='camd3'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_CCCAM" = "yes" ]; then
if [ "$(/etc/init.d/rc.cccam status)" = "stopped" ]; then
local ERROR_CAM='cccam'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_OSCAM" = "yes" ]; then
if [ "$(/etc/init.d/rc.oscam status)" = "stopped" ]; then
local ERROR_CAM='oscam'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_OSEMU" = "yes" ]; then
if [ "$(/etc/init.d/rc.osemu status)" = "stopped" ]; then
local ERROR_CAM='osemu'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_MPCS" = "yes" ]; then
if [ "$(/etc/init.d/rc.mpcs status)" = "stopped" ]; then
local ERROR_CAM='mpcs'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_NEWCS" = "yes" ]; then
if [ "$(/etc/init.d/rc.newcs status)" = "stopped" ]; then
local ERROR_CAM='newcs'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_SCAM" = "yes" ]; then
if [ "$(/etc/init.d/rc.scam status)" = "stopped" ]; then
local ERROR_CAM='scam'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_SBOX" = "yes" ]; then
if [ "$(/etc/init.d/rc.sbox status)" = "stopped" ]; then
local ERROR_CAM='sbox'
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_GBOX" = "yes" ]; then
if [ "$(/etc/init.d/rc.gbox status)" = "stopped" ]; then
local ERROR_CAM='gbox'
fi
fi
if [ -n "$ERROR_CAM" ]; then
get_ustor
if [ "$WATCHDOG_DO_CAMRUN" = "r" ]; then
local RESTART_OF="router reboot"
else
local RESTART_OF="$ERROR_CAM restart"
fi
ERROR_MSG="$RESTART_OF - $ERROR_CAM was down"
if [ "$WATCHDOG_DO_CAMRUN" != "r" ]; then /etc/init.d/rc.$ERROR_CAM restart; fi
echo "$(date) => $ERROR_MSG" >>$WORKING_DIR/$DAEMON.log
if [ "$WATCHDOG_SEND_CAMRUN" = "yes" ]; then transmit_mail; fi
if [ "$WATCHDOG_DO_CAMRUN" = "r" ]; then /sbin/reboot && exit 0; fi
fi
}
check_initerror() {
get_ustor
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_CAMD3" = "yes" ]; then
local CAMD3_LOG_FILE=${WATCHDOG_CAM_CAMD3_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "r02 Error activating card" $CAMD3_LOG_FILE)" ]; then
local ERROR_CAM='camd3'
local LOG_FILE=$CAMD3_LOG_FILE
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_CCCAM" = "yes" ]; then
local CCCAM_LOG_FILE=${WATCHDOG_CAM_CCCAM_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "card init fail" $CCCAM_LOG_FILE)" ]; then
local ERROR_CAM='cccam'
local LOG_FILE=$CCCAM_LOG_FILE
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_OSCAM" = "yes" ]; then
local OSCAM_LOG_FILE=${WATCHDOG_CAM_OSCAM_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "card initializing error" $OSCAM_LOG_FILE)" ]; then
local ERROR_CAM='oscam'
local LOG_FILE=$OSCAM_LOG_FILE
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_MPCS" = "yes" ]; then
local MPCS_LOG_FILE=${WATCHDOG_CAM_MPCS_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "card initializing error" $MPCS_LOG_FILE)" ]; then
local ERROR_CAM='mpcs'
local LOG_FILE=$MPCS_LOG_FILE
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_NEWCS" = "yes" ]; then
local NEWCS_LOG_FILE=${WATCHDOG_CAM_NEWCS_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "Reset failed" $NEWCS_LOG_FILE)" ]; then
local ERROR_CAM='newcs'
local LOG_FILE=$NEWCS_LOG_FILE
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_SCAM" = "yes" ]; then
local SCAM_LOG_FILE=${WATCHDOG_CAM_SCAM_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "card initializing error" $SCAM_LOG_FILE)" ]; then
local ERROR_CAM='scam'
local LOG_FILE=$SCAM_LOG_FILE
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_SBOX" = "yes" ]; then
local SBOX_LOG_FILE=${WATCHDOG_CAM_SBOX_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "card initializing error" $SBOX_LOG_FILE)" ]; then
local ERROR_CAM='sbox'
local LOG_FILE=$SBOX_LOG_FILE
fi
fi
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_GBOX" = "yes" ]; then
local GBOX_LOG_FILE=${WATCHDOG_CAM_GBOX_LOG_FILE/%uStor%/$USTOR_PATH}
if [ -n "$(grep "Reset failed" $GBOX_LOG_FILE)" ]; then
local ERROR_CAM='gbox'
local LOG_FILE=$GBOX_LOG_FILE
fi
fi
if [ -n "$ERROR_CAM" ]; then
if [ "$WATCHDOG_DO_CARDINIT" = "r" ]; then
local RESTART_OF="router reboot"
else
local RESTART_OF="$ERROR_CAM restart"
fi
ERROR_MSG="$RESTART_OF - $ERROR_CAM card initializing error"
/etc/init.d/rc.$ERROR_CAM stop
echo "$(date) => $ERROR_MSG" >>$WORKING_DIR/$DAEMON.log
rm -rf $LOG_FILE
if [ "$WATCHDOG_SEND_CARDINIT" = "yes" ]; then transmit_mail; fi
if [ "$WATCHDOG_DO_CARDINIT" = "r" ]; then /sbin/reboot && exit 0; else /etc/init.d/rc.$ERROR_CAM start; fi
fi
}
check_bulkwrite() {
get_ustor
if [ -z "$ERROR_CAM" -a "$WATCHDOG_CAM_OSCAM" = "yes" ]; then
local OSCAM_LOG_FILE=${WATCHDOG_CAM_OSCAM_LOG_FILE}
if [ -n "$(grep "usb bulk write failed" $OSCAM_LOG_FILE)" ]; then
local ERROR_CAM='oscam'
local LOG_FILE=$OSCAM_LOG_FILE
fi
fi
if [ -n "$ERROR_CAM" ]; then
if [ "$WATCHDOG_DO_CARDINIT" = "r" ]; then
local RESTART_OF="router reboot"
else
local RESTART_OF="$ERROR_CAM restart"
fi
ERROR_MSG="$RESTART_OF - $ERROR_CAM usb bulk write failed"
/etc/init.d/rc.$ERROR_CAM stop
echo "$(date) => $ERROR_MSG" >>$WORKING_DIR/$DAEMON.log
rm -rf $LOG_FILE
if [ "$WATCHDOG_SEND_BULKWRITE" = "yes" ]; then transmit_mail; fi
if [ "$WATCHDOG_DO_BULKWRITE" = "r" ]; then /sbin/reboot && exit 0; else /etc/init.d/rc.$ERROR_CAM start; fi
fi
}
check_dyndns() {
ERROR_MSG="dsld restart - dynamic DNS problems"
if [ "$(ping -c4 google.de | grep -c seq)" -eq 4 ]; then
if [ "$WATCHDOG_DYNDNS_INTERNAL" = "yes" ]; then
local CHECKING_ADDRESS="$(sed 's/.*[ \t]//g' /var/tmp/ddnsstat.txt 2>/dev/null)"
else
local CHECKING_ADDRESS="$WATCHDOG_DYNDNS"
fi
if [ "$(ping -c4 $CHECKING_ADDRESS | grep -c seq)" -ne 4 ]; then
local RESTART_DSLD='y'
fi
if [ -n "$RESTART_DSLD" ]; then
get_ustor
echo "$(date) => $ERROR_MSG" >>$WORKING_DIR/$DAEMON.log
if [ "$WATCHDOG_SEND_DYNDNS" = "yes" ]; then transmit_mail; fi
/etc/init.d/rc.dsld restart
fi
fi
}
check_reboot() {
get_ustor
ERROR_MSG="router reboot"
echo "$(date) => $ERROR_MSG" >>$WORKING_DIR/$DAEMON.log
if [ "$WATCHDOG_SEND_REBOOT" = "yes" ]; then transmit_mail; fi
}
case $1 in
""|load)
modreg cgi 'watchdog' 'Watchdog'
modreg daemon $DAEMON
if [ "$WATCHDOG_ENABLED" = "yes" ]; then
start
else
cleanup
echo "${DAEMON_LONG_NAME} is disabled." 1>&2
exit 1
fi
;;
unload)
modunreg daemon $DAEMON
modunreg cgi 'watchdog'
stop
;;
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
get_status
case $? in
0)
echo 'running'
;;
3)
echo 'stopped'
;;
esac
;;
c_cr)
check_camrunning
;;
c_ie)
check_initerror
;;
c_bw)
check_bulkwrite
;;
c_dd)
check_dyndns
;;
c_rb)
check_reboot
;;
*)
echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2
exit 1
;;
esac
exit 0
Watchdog Log-Verzeichnis:
Prüfintervall:
Softcam Aktivität prüfen
Bei Ausfall: Neustart von Softcam Router
Karten Initialisierung prüfen
Bei Fehler: Neustart von Softcam Router
USB (bulkwrite) prüfen
Bei Fehler: Neustart von Softcam Router
Dynamic DNS prüfen
Adresse:
COMMENTA