Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- HOST=$1 # Resolvable host name or IP address of remote host.
- TIMEOUT=$2
- format_time() {
- seconds=$1
- time=`printf "%02d-%02d-%02d\n" $[seconds/3600] $[$[seconds%3600]/$[60]] $[$[seconds%3600]%$[60]]`
- echo $time
- }
- wait_for_reboot() {
- cnt=0
- host=$1
- start=`date +%s`
- ping -c 1 -n -w 1 $host | grep "1 received" > /dev/null
- [ $? != 0 ] && status=down || status=up
- [ "$2" == "" ] && timeout=90 || timeout=$2
- echo
- echo -n "Waiting for host \"$host\" to come online: "
- while true; do
- ping -c 1 -n -w 1 $host | grep "0 received" > /dev/null
- result=$?
- echo -n "."
- cnt=$((cnt+1))
- [ $result == 1 ] && sleep 1 || status=down
- [ $result == 1 ] && [ $status == "down" ] && {
- sleep 1
- end=`date +%s`
- echo -e "\nHost \"$host\" is back online, reboot time: $(format_time $[end-start])"
- break
- } || [ $cnt -ge $timeout ] && {
- end=`date +%s`
- echo -e "\nRemote host \"$host\" did not reboot. [timeout > $timeout]\n"
- break
- }
- done
- }
- echo
- ssh root@$HOST reboot
- wait_for_reboot $HOST $TIMEOUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement