Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- check_online()
- {
- myHost=$1
- pingcount=`ping -c 4 $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }'`
- if [ "$pingcount" -eq 0 ]; then
- # 100% failed
- return 0
- else
- return 1
- fi
- }
- wait_for_offline()
- {
- timeout=$2
- timeoutcount=0
- check_online "$1"
- onlinenow="$?"
- while [ $onlinenow -eq 1 -a $timeoutcount -lt $timeout ]; do
- echo "$1 : $timeoutcount seconds and still online, waiting for offline..."
- timeoutcount=`expr $timeoutcount + 15`
- sleep 15
- check_online "$1"
- onlinenow="$?"
- done
- if [ $onlinenow -eq 0 ]; then
- echo "$1 : is offline after $timeoutcount seconds"
- return 1
- else
- echo "$1 : timeout on going offline after $timeoutcount seconds"
- return 0
- fi
- }
- shutdown_server()
- {
- check_online "$1"
- online="$?"
- if [ $online -eq 1 ]; then
- echo "$1 : detected online, need to shutdown"
- echo "Executing: shutdown"
- ssh root@$1 'shutdown -h now'
- wait_for_offline $1 120
- offline="$?"
- if [ $offline -eq 1 ]; then
- echo "$1 : Successfully shutdown at $(date)"
- return 0
- else
- echo "$1 : Timeout waiting to shutdown at $(date)"
- return 1
- fi
- else
- echo "$1 : Not online, no need to shutdown."
- return 0
- fi
- }
- echo "Starting shutdown process at $(date)"
- shutdown_server "farm"
- exit 0 #ignore failures at this point, just exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement