Advertisement
Uno-Dan

Wait for Reboot

Jul 12th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.90 KB | None | 0 0
  1. wait_for_reboot() {
  2.     cnt=0
  3.     host=$1
  4.     start=`date +%s`
  5.    
  6.     ping -c 1 -n -w 1 $host | grep "1 received" > /dev/null
  7.     [ $? != 0 ] && status=down || status=up
  8.     [ "$2" == "" ] && timeout=90 || timeout=$2
  9.    
  10.     echo -en "\nWaiting for target host \"$host\" to reboot."
  11.    
  12.     while true; do
  13.         ping -c 1 -n -w 1 $host | grep "0 received" > /dev/null
  14.         result=$?
  15.        
  16.         echo -n "."
  17.         cnt=$((cnt+1))
  18.         [ $result == 1 ] && sleep 1 || status=down
  19.        
  20.         [ $result == 1 ] && [ $status == "down" ] && {
  21.             sleep 1
  22.             end=`date +%s`
  23.             echo -e "Done\n\nHost \"$host\" is back online, reboot time: $(format_time1 $[end-start])"
  24.             break
  25.         } || [ $cnt -ge $timeout ] && {
  26.             echo -e "\nRemote host \"$host\" did not reboot. [timeout > $timeout]\n"
  27.             break
  28.         }
  29.     done
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement