Created
November 2, 2011 00:40
-
-
Save distributedlife/1332492 to your computer and use it in GitHub Desktop.
Run a script if a process is not running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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