Last active
December 14, 2015 18:59
-
-
Save spacelis/5133152 to your computer and use it in GitHub Desktop.
Sending out notifications when either the daemon or the target process stop running.
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
#!/usr/bin/env bash | |
if [[ $# < 2 ]]; then | |
echo "Usage: watchdog <pcs> <email>" | |
exit 1 | |
fi | |
svr="$(hostname)" | |
pcs=$1 | |
pcsdetail=$(ps --no-heading -p $pcs) | |
email=$2 | |
trap "printf \"Daemon died on $svr!\\n \" | mail -s \"Daemon died on $svr!\" $email" 0 | |
read -d '' script <<"EOF" | |
import sys; | |
import os; | |
import time; | |
while os.path.exists('/proc/pid'): | |
time.sleep(10); | |
EOF | |
python <<< "${script/pid/$pcs}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment