A rather simplistic script to ensure a program is not started if it is already running:
if [ ! -z "$PROCESSNAME" ] && [ ! -z "`ps -e | grep $PROCESSNAME`" ]
# Replace the echo statement below with the desired command(s)
echo $1 is not running
Beware this an be a little tricky. You must know the process name as it shows in the process list, not search for the binary name. For example: under Debian, Firefox is known as Iceweasel, but ps -e
lists the process as "firefox-bin". Firefox's process name under Mint is simply "firefox"
Also note that if you only use parts of the process name, it will evaluate as true. Of course this can be taken care of with a little awkery.
Also in my original test script, I used a parameter passed to the script rather than $PROCESSNAME, which would make this more generic, and possibly more useful. Simply delete the line "PROCESSNAME=" and change $PROCESSNAME to $1 in the conditionals.