Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- IPGROUP="192.168.1.35 192.168.1.36 192.168.1.2" # any number, space delimited
- IPCOUNT="3" # number of machines being tested
- MAXFAILS="5" # Total number of fails before shutdown
- INTERVAL="10" # time in seconds between tests
- #If MAXFAILS is 5 and INTERVAL is 10, then you're looking at about a minute
- # of all machines being down before the NAS powers off
- COUNT="0" # reset COUNTer
- UPMACHINES="0" # pass/fail indicator
- DEBUG="1" # 1 for DEBUGging, 0 for not
- while [ "$MAXFAILS" != "$COUNT" ];
- do
- if [ "1" == $DEBUG ]; then echo "MAXFAILS=$MAXFAILS COUNT=$COUNT"; fi
- UPMACHINES=$IPCOUNT # Reset indicator
- if [ "1" == $DEBUG ]; then echo "UPMACHINES=$UPMACHINES"; fi
- for IP in $IPGROUP; do # This is where the space delimiting expands to multiple parameters
- # The variable $IPGROUP is not quoted for a reeason, do not "correct" it
- /sbin/ping -c 1 "$IP"
- if [ $? != "0" ]; then
- UPMACHINES=$((UPMACHINES-1)) #decrease number of running machines detected
- if [ "1" == $DEBUG ]; then echo "IP=$IP UPMACHINES=$UPMACHINES"; fi
- fi
- done
- if [ 0 == $UPMACHINES ]; then COUNT=$((COUNT+1)); else COUNT="0"; fi
- # If all IPs failed, increment COUNTer, otherwise, zero it
- sleep $INTERVAL
- done
- echo "Shutting down. no response(s) from any of $IPGROUP"
- /sbin/shutdown -p now
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement