EatonNmc66102Reboot
#!/bin/sh
# This script conditionally reboots an Eaton NMC 66102 invoking wget under Linux.
# The Eaton UPS network management card is only rebooted in the case that its
# current time is completely wrong. The latter typically occurs after a power-on
# cycle, whereat the network components are powered by the UPS itself such that
# the network is not available right from the beginning. For the usual reasons,
# the card's NTPD refuses to update the time stepping from the year 1970 to now.
# Hence, the card can run with time values near 1970 for a very long time which
# is not desirable, of course.
# The NMC 66102 here has the technical level 15 and the firmware revision HF.
# This script has been tested under Debian Lenny with wget 1.11.4,
# and under DD-WRT v24-sp2 (12/14/11) std - build 18007 on a Gateworks GW2358-4
# router with wget_1.13.4-1_ixp4xx.ipk from http://downloads.openwrt.org.
# No write access is necessary, except for /dev/stdout and friends, of course.
# This script was originally written by Stephan Seidl in 2010,
# no copyright is claimed. It is offered as-is, without any warranty.
# This script is in the public domain; do with it what you wish.
# This script changed in 2012, now accessing the NMC 66102 using SSL.
unset LANG LC_ALL
LC_ALL=C
export LC_ALL
WGET=/jffs/usr/bin/wget
HOSTNAME=ups1.snet
USER="<user>"
PASSWORD="<passwd>"
test -x ${WGET} || WGET=wget
accessdata=/jffs/usr/bin/SmallSystemsAccessData
test -e ${accessdata} || accessdata=/jffs/etc/SmallSystemsAccessData
test -e ${accessdata} || accessdata=/etc/SmallSystemsAccessData
if [ -r ${accessdata} ]; then
. ${accessdata}
USER="${ups1_user}"
PASSWORD="${ups1_passwd}"
fi
cmd="${WGET}"
cmd="${cmd} --no-check-certificate"
cmd="${cmd} --secure-protocol=TLSv1"
cmd="${cmd} --user=${USER} --password=${PASSWORD}"
cmd="${cmd} -o /dev/null -O -"
cmd="${cmd} https://${HOSTNAME}/ups_propStatus.htm"
out=`${cmd} 2>/dev/null` || :
hostdate=`date -Iseconds`
out=`echo "${out}" | tr '\015' ' '`
out=`echo "${out}" | tr '\011' ' '`
out=`echo "${out}" | tr '[A-Z]' '[a-z]'`
out=`echo "${out}" | tr '"' '@'`
out=`echo "${out}" | sed 's,@,,g'`
out=`echo "${out}" | sed 's,<,@<,g'`
out=`echo "${out}" | sed 's,>,>@,g'`
out=`echo "${out}" | tr '@' '\012'`
out=`echo "${out}" | sed 's,< *b *>,,g'`
out=`echo "${out}" | sed 's,< *font *..* *>,,g'`
out=`echo "${out}" | sed 's,< */font *>,,g'`
out=`echo "${out}" | sed 's,last ,@last ,g'`
out=`echo "${out}" | sed 's,<,@<,g'`
out=`echo "${out}" | tr '\012' ' '`
out=`echo "${out}" | tr '@' '\012'`
out=`echo "${out}" | sed -n 's,last *update *: *,,p'`
out=`echo "${out}" | sed 's, *, ,g'`
out=`echo "${out}" | sed 's,^ ,,'`
out=`echo "${out}" | sed 's, $,,'`
carddate="${out}"
if [ -z "${carddate}" ]; then
carddate="${hostdate}"
carddate=`echo "${carddate}" | tr 'T' ' '`
carddate=`echo "${carddate}" | tr '-' '/'`
carddate=`echo "${carddate}" | sed 's,.[0-9][0-9][0-9][0-9]$,,'`
fi
carddate=`echo "${carddate}" | tr '/' ' '`
carddate=`echo "${carddate}" | tr ':' ' '`
hostdate=`echo "${hostdate}" | sed 's,^ *,,'`
hostdate=`echo "${hostdate}" | sed 's, *$,,'`
hostdate=`echo "${hostdate}" | tr '-' ' '`
hostdate=`echo "${hostdate}" | tr 'T' ' '`
hostdate=`echo "${hostdate}" | tr ':' ' '`
hostdate=`echo "${hostdate}" | tr '+' ' '`
cardyear=`echo "${carddate}" | cut -f1 -d' '`
hostyear=`echo "${hostdate}" | cut -f1 -d' '`
cardmonth=`echo "${carddate}" | cut -f2 -d' '`
hostmonth=`echo "${hostdate}" | cut -f2 -d' '`
cardday=`echo "${carddate}" | cut -f3 -d' '`
hostday=`echo "${hostdate}" | cut -f3 -d' '`
cardhour=`echo "${carddate}" | cut -f4 -d' '`
hosthour=`echo "${hostdate}" | cut -f4 -d' '`
cardminute=`echo "${carddate}" | cut -f5 -d' '`
hostminute=`echo "${hostdate}" | cut -f5 -d' '`
diff="0"
diff="${diff} ${cardyear} ${hostyear} - + 12 * "
diff="${diff} ${cardmonth} ${hostmonth} - + 31 * "
diff="${diff} ${cardday} ${hostday} - + 24 * "
diff="${diff} ${cardhour} ${hosthour} - + 60 * "
diff="${diff} ${cardminute} ${hostminute} - + 1 * "
diff="${diff} p "
diff=`echo "${diff}" | dc 2>/dev/null`
diff=`echo "${diff}" | sed 's,^ *,,'`
diff=`echo "${diff}" | sed 's, *$,,'`
diff=`echo "${diff}" | sed 's,^-,,'`
test="${diff}"
test=`echo "${test}" | tr '[0-8]' '999999999'`
test=`echo "${test}" | sed 's,^99*$,9,'`
test "${test}" = "9" || diff="999"
if [ ${diff} -gt 5 ]; then
# Reboot, disturbing e-mail will arrive.
cmd="${WGET}"
cmd="${cmd} --tries=4 --timeout=20"
cmd="${cmd} --no-check-certificate"
cmd="${cmd} --secure-protocol=TLSv1"
cmd="${cmd} --user=${USER} --password=${PASSWORD}"
cmd="${cmd} -o /dev/null -O /dev/null"
cmd="${cmd} --post-data=BeforeReset='&'Submit=Reset+Communication"
cmd="${cmd} https://${HOSTNAME}/Forms/set_sys_2"
eval "${cmd}" 2>/dev/null || :
fi
Stephan K.H. Seidl