Skip to content

Instantly share code, notes, and snippets.

@Super-Chama
Created January 1, 2023 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Super-Chama/ee05f0cfb68717fc3fa2a1942f784909 to your computer and use it in GitHub Desktop.
Save Super-Chama/ee05f0cfb68717fc3fa2a1942f784909 to your computer and use it in GitHub Desktop.
Shell script to schedule shutdown if web service is not reachable
#!/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