I have the last portion of an Open Step ping server shell script that is giving me issues that I need to adapt to Ubuntu 8.10 Client flavor of Unix. Can someone see what is wrong with the following:
# if there are servers that just went down or came back up, notify
# with high importance
if [ -s /tmp/$SCRIPTNAME.serverlist.upagain -o -s /tmp/$SCRIPTNAME.serverlist.wentdown ]; then
echo notifying of servers that are up again or just now down
notify high
# if there is no new news, but servers are still down from before,
# notify only once per day, with low importance
elif [ -s /tmp/$SCRIPTNAME.serverlist.stilldown ]; then
if [ "`date | awk '{print $4}' | awk -F: '{print $1}'`" -eq 11 ]; then
if [ ! -f /tmp/$SCRIPTNAME.stilldownsent ]; then
touch /tmp/$SCRIPTNAME.stilldownsent
echo notifying once today of servers that are still down from before
notify low
fi
else
echo not time for daily notification of servers that are still down
if [ -f /tmp/$SCRIPTNAME.stilldownsent ]; then
rm /tmp/$SCRIPTNAME.stilldownsent
fi
fi
else
echo no notification to make
fi
so the script ends or errors out and I think its the syntax specifically in my date command is not Ubuntu friendly- does anyone know the Ubuntu variety of Unix enough to give me a hand? Many thanks!! Dale
I'll give it a try. THANKS SO MUCH! This forum has been very helpful to me. I will be back in touch. Did you see anything else that looked suspicious? Dale
Yeah, that works - THANKS! I can see the integer comparing itself againist 11 - very nice. but the script is still ending and not notifying the update (when a server comes back up). The script is supposed to compare from the last time it ran and current time it runs and update files with the results and compare them to see if there are any changes. If there are, it should email the updates. Would you mind taking another look?
Current output when script runs
+ read NAME IP ROUTER
++ grep -w Winchester2 /admin/scripts/crons/ping_servers.sh.serverlist.downlastrun
+ WASDOWN=
++ grep -w Winchester2 /admin/scripts/crons/ping_servers.sh.serverlist.down
+ ISDOWN=
+ '[' -n '' ']'
+ '[' -n '' ']'
+ '[' -z '' ']'
+ '[' -n '' ']'
+ read NAME IP ROUTER
+ '[' -s /tmp/ping_servers.sh.serverlist.upagain -o -s /tmp/ping_servers.sh.serverlist.wentdown ']'
+ '[' -s /tmp/ping_servers.sh.serverlist.stilldown ']'
++ date +%H
+ '[' 12 -eq 11 ']'
+ echo not time for daily notification of servers that are still down
not time for daily notification of servers that are still down
+ '[' -f /tmp/ping_servers.sh.stilldownsent ']'
root@mpt1a02:/admin/scripts/crons#
Here is the code of the script where it compares:
# look for differences
# in this section, we are looking for what servers just went down,
# which ones just came back up, and which ones are still down from before
echo lists of recent downs and returns, and servers that remain down
>/tmp/$SCRIPTNAME.serverlist.wentdown
>/tmp/$SCRIPTNAME.serverlist.stilldown
>/tmp/$SCRIPTNAME.serverlist.upagain
while read NAME IP ROUTER
do
WASDOWN=`grep -w $NAME /admin/scripts/crons/$SCRIPTNAME.serverlist.downlastru
n`
ISDOWN=`grep -w $NAME /admin/scripts/crons/$SCRIPTNAME.serverlist.down`
if [ -n "$WASDOWN" -a -n "$ISDOWN" ]; then
echo "$ISDOWN (still down)" >>/tmp/$SCRIPTNAME.serverlist.stilldown
fi
if [ -n "$WASDOWN" -a -z "$ISDOWN" ]; then
echo "$NAME $IP $ROUTER (up again)" >>/tmp/$SCRIPTNAME.serverlist.upagain
fi
if [ -z "$WASDOWN" -a -n "$ISDOWN" ]; then
echo "$ISDOWN (just went down)" >>/tmp/$SCRIPTNAME.serverlist.wentdown
fi
done</tmp/$SCRIPTNAME.serverlist
# cat /tmp/$SCRIPTNAME.serverlist.upagain /tmp/$SCRIPTNAME.serverlist.wentdown /
tmp/$SCRIPTNAME.serverlist.stilldown