1

I have a shell script like this.

#!/bin/sh

s=$1      

pro=`ps -ef | grep $s | grep -v grep | grep -v test3.sh | wc -l`

 if [ $pro -eq 0 ] 
    then
            echo "Service $s is DOWN..."
            echo "Service $s is DOWN..." >> processlogs.txt
            echo "Starting Service $s..."
            echo "Starting Service $s..." >> processlogs.txt
            java -jar clientApplication.jar $s &

 else
            echo "Service $s is Running..."
            echo "Service $s is Running..." >> processlogs.txt

 fi

When I execute the shell script, and the operation enters in the if condition it never come back. It continuously executes the command "java -jar clientApplication.jar $s". But there is no problem in else condition. Is my syntax wrong or any logical error.

Thanks ...

1
  • $pro will always be at least 1 since you are setting 's' to $1 and $1 should show up in ps -ef | grep $s Commented Feb 13, 2013 at 5:39

1 Answer 1

1

You should try this ...

(java -jar clientApplication.jar $s &)

... instead of ...

java -jar clientApplication.jar $s &

and if that does work take a look at nohup

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Red Cricket but both doesnot work. It works in VMware in ip 100.100.100.186 but it doesnot work in ip 100.100.100.7 . Can ip be the factor for it.
I guess that depend more on what clientApplication.jar does. If it is your code I would suggest daemonizing it so that you wouldn't have to worry about back-grounding with a shell script.
clientApplication just takes arguments and print continuously.
then IP address shouldn't matter. So why does this java program need IP address to just print continuously?
program dont need ip. Previously I was testing in VMware and now I am testing in different computer having linux environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.