Simple Script to Check running Process

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 05-02-2011
Java Simple Script to Check running Process

Code:
#!/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.

Code:
'if' unmatched

Any advice would be great thanks!

William
# 2  
Old 05-02-2011
remove else and try
# 3  
Old 05-02-2011
Nope that threw another error?


Code:
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
# 4  
Old 05-02-2011
also
"$CHECK = 0" is wrong . should be $CHECK -eq 0
# 5  
Old 05-02-2011
Changed that aswell but it doesn't like the last line "FI"

Same error as before..
# 6  
Old 05-02-2011
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
# 7  
Old 05-02-2011
Copied and Pasted that straight in but its still throwing an

Code:
unexpected operator/operand

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

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Check if process is running if not then use command kotch Shell Programming and Scripting 2 09-23-2018 03:57 AM
ksh script to check if certain process is running seekryts15 Shell Programming and Scripting 6 12-29-2014 01:41 PM
How to add conditional check of whether a process is running before doing rest of script? nbsparks Shell Programming and Scripting 14 09-23-2013 12:57 PM
How a process can check if a particular process is running on different machine? saurabhnsit2001 UNIX for Dummies Questions & Answers 2 06-03-2012 12:14 AM
need to check if the process is running shifahim Shell Programming and Scripting 8 08-18-2011 11:17 PM
Script to check running of process lovepujain Shell Programming and Scripting 2 04-25-2011 03:39 AM
How do I check if a process is running in C cprogdude Programming 1 10-12-2010 06:01 AM
How to check if process is running? ladyAnne UNIX and Linux Applications 5 05-01-2010 02:20 AM
Check if Process is running Raynon Shell Programming and Scripting 3 01-08-2010 03:03 AM
How to write an expect script to check if a process is running? icchi Shell Programming and Scripting 5 10-27-2009 04:05 AM
How to check since when (for how long) a particular process is running ? hpuxlxboy UNIX for Advanced & Expert Users 2 02-19-2009 08:14 AM
script to check if process is running daydreamer Shell Programming and Scripting 2 01-28-2009 06:14 PM
how to check if a process is running in a server from shell script. debu UNIX for Advanced & Expert Users 2 01-24-2008 05:19 PM
check process running rose1207 Shell Programming and Scripting 4 12-28-2007 01:23 AM
script to check for a particular process and alert if its not running goks Shell Programming and Scripting 1 12-09-2005 05:11 AM