Question : Linux script to check if a pid is running then executing another script

I have a java application that starts with the following java command
$JAVA_HOME/jre/bin/java -Dswing.noxp=true -Djava.library.path=/usr/local/OpenEPS:/usr/lib -classpath .:$CLASSPATH com.retailJava.ltd.javaPOS.UI.TPOS.POSApplication $DEVICE_ID

I would like to have a command before this that checks if the pid (TPOS.POSApplication) is running, if it is echo Application running, if not execute the java string above.
Im not versed in scripting so I'm looking for a simple if statement that will do something like

BASHPID=pstree -a | grep TPOS.POSApplication
if $=TPOS.POSApplication
echo "Application allready running"
else
       $JAVA_HOME/jre/bin/java -Dswing.noxp=true -Djava.library.path=/usr/local/OpenEPS:/usr/lib -classpath .:$CLASSPATH com.retailJava.ltd.javaPOS.UI.TPOS.POSApplication $DEVICE_ID
fi


what I have will not work I dont think its all correct please help with any syntax errors I have here.
Thanks

Answer : Linux script to check if a pid is running then executing another script

BASHPID=$(pstree -a| grep TPOS.POSApplication)
if  [[ ! -z $BASHPID ]]  ; then
echo "Application already running"
else
      $JAVA_HOME/jre/bin/java -Dswing.noxp=true -Djava.library.path=/usr/local/OpenEPS:/usr/lib -classpath .:$CLASSPATH com.retailJava.ltd.javaPOS.UI.TPOS.POSApplication $DEVICE_ID
fi

Please make sure that the variables $JAVA_HOME, $CLASSPATH and $DEVICE_ID are set correctly! This is particularly important when starting the script via cron!

wmp

Random Solutions  
 
programming4us programming4us