Skip to content

Instantly share code, notes, and snippets.

@auckenox
Last active November 4, 2016 21:55
Show Gist options
  • Save auckenox/6e61db976892b691c59f1a59cc1b4b60 to your computer and use it in GitHub Desktop.
Save auckenox/6e61db976892b691c59f1a59cc1b4b60 to your computer and use it in GitHub Desktop.
basic watchdog for python (or other) scripts
#!/bin/bash
watchdog () {
datum=$(date -u)
scna="$(basename $1)"
ps -ef | grep $1 | grep -v grep;
if [[ $? -eq 0 ]]; then
echo "$datum - OK, $scna is running";
else
echo "$datum - $1 died, resurrecting $scna now...";
screen -d -m -S $scna /usr/bin/python $1 2>&1 /dev/null
fi
}
watchdog "/home/pi/locker-btn1.py"
watchdog "/home/pi/locker-btn2.py"
# add a cronjob to this script, one at reboot and one every minute */1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment