Simple Script to Check running Process | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Simple Script to Check running Process

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-02-2011
will_123 will_123 is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 May 2011, 3:15 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 05-02-2011
kd09714 kd09714 is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 15 January 2012, 4:51 AM EST
Posts: 27
Thanks: 0
Thanked 1 Time in 1 Post
remove else and try
Sponsored Links
    #3  
Old 05-02-2011
will_123 will_123 is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 May 2011, 3:15 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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
kd09714 kd09714 is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 15 January 2012, 4:51 AM EST
Posts: 27
Thanks: 0
Thanked 1 Time in 1 Post
also
"$CHECK = 0" is wrong . should be $CHECK -eq 0
Sponsored Links
    #5  
Old 05-02-2011
will_123 will_123 is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 May 2011, 3:15 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Changed that aswell but it doesn't like the last line "FI"

Same error as before..
Sponsored Links
    #6  
Old 05-02-2011
kd09714 kd09714 is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 15 January 2012, 4:51 AM EST
Posts: 27
Thanks: 0
Thanked 1 Time in 1 Post
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
Sponsored Links
    #7  
Old 05-02-2011
will_123 will_123 is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 May 2011, 3:15 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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"
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to check running of process lovepujain Shell Programming and Scripting 2 04-25-2011 03:39 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
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
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



All times are GMT -4. The time now is 10:25 AM.