Skip to content

Instantly share code, notes, and snippets.

@spacelis
Last active December 14, 2015 18:59
Show Gist options
  • Save spacelis/5133152 to your computer and use it in GitHub Desktop.
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.
#!/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