Skip to content

Instantly share code, notes, and snippets.

@danielestevez
Created August 10, 2023 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielestevez/46d46711d72fef46d95f890aa3624ad5 to your computer and use it in GitHub Desktop.
Save danielestevez/46d46711d72fef46d95f890aa3624ad5 to your computer and use it in GitHub Desktop.
Keep alive Bash script to check, log and restart a process
#!/bin/bash
process_name="xxxxx"
if ! pgrep -x "$process_name" > /dev/null; then
echo "The process $process_namen was not running at " $(date -u) >> ~/keep_alive.log
./xxxxxx &
echo "The process $process_namen was restarted at " $(date -u) >> ~/keep_alive.log
fi
# crontab expression to run check every 5 mins
# */5 * * * * ./keep_alive.sh >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment