Created
June 19, 2024 11:23
-
-
Save krisf/e81d082a0b64dd7db99b22b851bbfecb to your computer and use it in GitHub Desktop.
ping check two LAN hosts, if it fails twice in a row (15min cron job) notify user and shut down the unraid server gracefully
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
#!/usr/bin/env bash | |
if ping -c 1 192.168.0.200 &> /dev/null | |
then | |
echo "ping success, exiting" | |
rm /tmp/failed_ping_touchfile | |
exit 0 | |
else | |
echo "ping fail, checking second host" | |
if ping -c 1 192.168.0.220 &> /dev/null | |
then | |
echo "ping2 success, exiting" | |
rm /tmp/failed_ping_touchfile | |
exit 0 | |
else | |
echo "ping2 fail, checking touchfile" | |
if [ -f /tmp/failed_ping_touchfile ] | |
then | |
echo "Touchfile exists, last ping check must have failed. Initiating shutdown." | |
/usr/local/emhttp/webGui/scripts/notify -i warning -s "Shutting down due to ping tested AC power loss" | |
echo "SHUTDOWN NOW" | |
powerdown | |
exit 1 | |
else | |
echo "File doesnt exist. Creating touchfile and exiting..." | |
touch /tmp/failed_ping_touchfile | |
/usr/local/emhttp/webGui/scripts/notify -i warning -s "AC POWER LOSS DETECTED. Shutdown soon..." | |
exit 1 | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment