Last active
November 1, 2022 18:01
-
-
Save bboozzoo/e038a7835675841d05d5e94e4c61359d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export LC_ALL=C | |
IP="${1-192.168.100.12}" | |
SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=5" | |
cnt=0 | |
old_boot_id="" | |
while true; do | |
cnt=$((cnt+1)) | |
echo "------ $(date) attempt $cnt" | |
failcnt=0 | |
while ! ssh $SSH_OPTS "root@${IP}" "uptime"; do | |
failcnt=$((failcnt+1)) | |
echo "----- $(date) failed attempt $failcnt" | |
if [ "$failcnt" -gt 30 ]; then | |
echo "---- $(date) unable to reboot: BAD STATE" | |
exit 5 | |
fi | |
sleep 5 | |
done | |
new_boot_id="$(ssh $SSH_OPTS "root@${IP}" "cat /proc/sys/kernel/random/boot_id")" | |
if [ -n "$old_boot_id" ] && [ "$new_boot_id" = "$old_boot_id" ]; then | |
echo "----- $(date) ERROR: reboot didn't work" | |
exit 4 | |
fi | |
old_boot_id="$new_boot_id" | |
ssh $SSH_OPTS "root@${IP}" "reboot" | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment