Created
January 1, 2023 19:41
-
-
Save Super-Chama/ee05f0cfb68717fc3fa2a1942f784909 to your computer and use it in GitHub Desktop.
Shell script to schedule shutdown if web service is not reachable
This file contains hidden or 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 | |
IP='192.168.1.1' | |
DELAY=5 | |
DATE=$(date '+%d/%m/%Y %H:%M:%S') | |
ping -c 1 $IP &> /dev/null | |
if [[ $? -ne 0 ]]; | |
then | |
echo "LOST CONNECTION @ "$DATE | |
/sbin/shutdown -h +$DELAY | |
else | |
echo "OK @ "$DATE | |
/sbin/shutdown -c | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment