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
- wait_for_host() {
- cnt=0
- host=$1
- status=up
- timeout=$2
- ping -c 1 -n -w 1 $host | grep "1 received" > /dev/null
- result=$?
- [ $result != 0 ] && status=down
- echo
- echo -n "Waiting for host \"$host\" to come back online: "
- while true; do
- ping -c 1 -n -w 1 $host | grep "0 received" > /dev/null
- result=$?
- echo -n "."
- [ $result == 1 ] && { sleep 1; cnt=$((cnt+1)); }
- if [ $result == 1 ] && [ status == "up" ]; then
- continue
- elif [ $result == 0 ]; then
- status=down
- fi
- [ $result == 1 ] && [ $status == "down" ] && {
- sleep 1
- echo -e "\nHost \"$host\" is back online."
- break
- }
- if [ $cnt -ge $timeout ]; then
- echo -e "\nRemote host \"$host\" did not reboot.\n"
- break
- fi
- done
- }
- echo
- ssh root@$HOST reboot
- wait_for_host $HOST $TIMEOUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement