Skip to content

Instantly share code, notes, and snippets.

@distributedlife
Created November 2, 2011 00:40
Show Gist options
  • Save distributedlife/1332492 to your computer and use it in GitHub Desktop.
Save distributedlife/1332492 to your computer and use it in GitHub Desktop.
Run a script if a process is not running
#!/bin/bash -e
#$1 = the regex to identify the job; should use the pattern "[m]y job"
#$2 = the script to run
REGEX=$1
SCRIPT=$2
#try and get the PID
PSID=`ps -ef | grep "$REGEX" -m 01 | awk '{print $2}'`
if [ "$PSID" != "" ]
then
echo 'the job is already running'
else
echo 'the job is not running, starting it using supplied script'
$SCRIPT
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment