Skip to content

Instantly share code, notes, and snippets.

@serg-kovalev
Last active August 29, 2015 14:04
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 serg-kovalev/e7d441da840f9e646063 to your computer and use it in GitHub Desktop.
Save serg-kovalev/e7d441da840f9e646063 to your computer and use it in GitHub Desktop.
This shell script checks if process exists and removes pid file if not. I use this script with monit to be sure that process exist before killing it
#!/usr/bin/env bash
# the first argument should be a path to pid file
if [[ -f "$1" ]] ; then
if [ $(ps -p $(cat $1) | wc -l) -gt 1 ] ; then
# process exists - do nothing
#echo "OK"
exit 0
else
#echo "will do rm $1"
rm $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment