Simple Script to Check running Process

#!/bin/sh

CHECK='ps aux | grep start.jar | grep -v grep | wc -l'

if [ $CHECK = 0 ]
then
	/usr/local/jre-1.7.0/bin/java - jar start.jar &
else
	
fi

Could anybody advise whats up with this code im trying to put this in as a cron job to check that solr search engine is running every 10secs and if its not start it. The script is giving me a error when i execute it.

'if' unmatched 

Any advice would be great thanks!

William

remove else and try

Nope that threw another error?

check.sh[9]: [: aux: unexpected operator/operand

The previous error was where i tried to enter exit at the end rather than fi.

I have very limited scripting experience so im trying to get my head around why this wont work?

Thanks

also
"$CHECK = 0" is wrong . should be $CHECK -eq 0

Changed that aswell but it doesn't like the last line "FI"

Same error as before..

check this

#!/bin/sh
CHECK='ps -aux | grep start.jar | grep -v grep | wc -l'
if [ $CHECK -eq 0 ]
then
/usr/local/jre-1.7.0/bin/java - jar start.jar &
fi

Copied and Pasted that straight in but its still throwing an

unexpected operator/operand

on line 6 this time which is again the "fi"

e.g for every 10 minutes control your jar is ok

*/10 * * * * [[ $(/bin/ps aux|/bin/grep java|grep "start.jar") ]] && /usr/local/jre-1.7.0/bin/java - jar start.jar &

I managed to get it fixed with help from KD.

Thanks!

#!/bin/sh
CHECK=`ps -aux | grep start.jar | grep -v grep | wc -l`
if [ $CHECK -eq 0 ]
then
/usr/local/jre-1.7.0/bin/java -jar /home/apache-solr-1.4.1/example/start.jar &
fi

Check pgrep

pgrep does not work on all unix flavor.