Skip to content

Instantly share code, notes, and snippets.

@discarn8
Last active January 6, 2024 22:14
Show Gist options
  • Select an option

  • Save discarn8/839e9643beadde266791629bfffe145e to your computer and use it in GitHub Desktop.

Select an option

Save discarn8/839e9643beadde266791629bfffe145e to your computer and use it in GitHub Desktop.
BASH_Program_Check
#! /bin/bash
# Add an entry in your crontab to run this script on a timed interval
logfile="/var/log/app_check.log"
case "$(pidof app | wc -w)" in
0) echo "App found not running, (re)starting app: $(date)" >> $logfile
DISPLAY=:0 /home/jdoe/app_script &
;;
1) echo "App found running, all OK: $(date)" >> $logfile
;;
*) echo "Multiple instances of app found running. Stopping & restarting app: $(date)" >> $logfile
kill $(pidof app | awk '{print $1}')
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment