# In DEBUG mode: generate some files under "/tmp" to see, the script is running
if [ "$DBG" = "dbg" ]
then
mkdir -p /tmp/Fujitsu/
tail $SCRIPTLOG 2>/dev/null > $SCRIPTLOG.bk
mv -f $SCRIPTLOG.bk $SCRIPTLOG
echo "$0 V__MP_VERSION__ last ran at `date`" >> $SCRIPTLOG
fi
EECD=`whereis eecd | awk 'NF>1{print $2}'`
if [ "$EECD" = "" ]
then
# either not a system from FUJITSU or no ServerView agents installed - do nothing!
[ "$DBG" = "dbg" ] && echo "Not a system from FUJITSU or ServerView Agents not installed."
exit 0
fi
# test that SNMP is installed
SNMP=`whereis snmpd | awk 'NF>1{print $2}'`
if [ "$SNMP" = "" ]
then
echo "SNMP is *NOT* installed! Cannot recover."
exit 0
fi
[ "$DBG" = "dbg" ] && echo "SNMP is installed at: $SNMP"
SERVICE=`ls -1 /etc/init.d/ /usr/lib/systemd/system/ 2>/dev/null | grep -i snmp | sed "s/.service//" | head -n 1`
# check if SNMP is running
SNMPRUNNING=`ps -A | grep -i '[s]nmpd'`
if [ "$SNMPRUNNING" = "" ]
then
echo "SNMP is not running, starting"
service $SERVICE start
exit 0
fi
[ "$DBG" = "dbg" ] && echo "SNMP is running"
# check if SNMP is listening
SNMPLISTENING=`netstat -nlu | grep 161 | wc -l`
if [ $SNMPLISTENING -lt 1 ]
then
echo "SNMP is not listening, restarting"
service $SERVICE restart
exit 0
fi
[ "$DBG" = "dbg" ] && echo "SNMP is listening"
[ "$DBG" = "dbg" ] && echo "Nothing to do"