diff options
author | Renato Botelho <garga@FreeBSD.org> | 2013-12-24 12:06:51 -0200 |
---|---|---|
committer | Renato Botelho <garga@FreeBSD.org> | 2013-12-24 12:06:51 -0200 |
commit | cd14bb1950262bb6447fc47db5bee494d6ce5f45 (patch) | |
tree | f542e757cbd93ee8b2e3436f3b930c496408b483 /usr/local | |
parent | 15bec71856363fcf85799e54dfaa5aa55e88bd81 (diff) | |
download | pfsense-cd14bb1950262bb6447fc47db5bee494d6ce5f45.zip pfsense-cd14bb1950262bb6447fc47db5bee494d6ce5f45.tar.gz |
On first run REVIOUSSTATUS doesn't exist, so it cannot be UP or DOWN, invert the logic to fix this. While I'm here, check if file exists before cat it
Diffstat (limited to 'usr/local')
-rwxr-xr-x | usr/local/bin/ping_hosts.sh | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/usr/local/bin/ping_hosts.sh b/usr/local/bin/ping_hosts.sh index 949a843..c8538a6 100755 --- a/usr/local/bin/ping_hosts.sh +++ b/usr/local/bin/ping_hosts.sh @@ -75,12 +75,15 @@ for TOPING in $PINGHOSTS ; do fi echo Processing $DSTIP # Look for a service being down + # Read in previous status + PREVIOUSSTATUS="" + if [ -f "/var/db/pingstatus/${DSTIP}" ]; then + PREVIOUSSTATUS=`cat /var/db/pingstatus/$DSTIP` + fi $PINGCMD -c $COUNT -S $SRCIP $DSTIP if [ $? -eq 0 ]; then # Host is up - # Read in previous status - PREVIOUSSTATUS=`cat /var/db/pingstatus/$DSTIP` - if [ "$PREVIOUSSTATUS" = "DOWN" ]; then + if [ "$PREVIOUSSTATUS" != "UP" ]; then # Service restored if [ "$SERVICERESTOREDSCRIPT" != "" ]; then echo "$DSTIP is UP, previous state was DOWN .. Running $SERVICERESTOREDSCRIPT" @@ -91,8 +94,7 @@ for TOPING in $PINGHOSTS ; do fi else # Host is down - PREVIOUSSTATUS=`cat /var/db/pingstatus/$DSTIP` - if [ "$PREVIOUSSTATUS" = "UP" ]; then + if [ "$PREVIOUSSTATUS" != "DOWN" ]; then # Service is down if [ "$FAILURESCRIPT" != "" ]; then echo "$DSTIP is DOWN, previous state was UP .. Running $FAILURESCRIPT" |