0

I have a shell script like this.

 #!/bin/sh

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

echo $pro
echo $pro1

if [ $pro1 -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" &
            exit 0

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

   fi

Now I want the value of $s to java program. What should I do for this. Thanks.

2
  • I just want ti insert the log in database from java application. Commented Feb 7, 2013 at 4:54
  • Maybe you could provide some more explanation. Are you simply trying to write the equivalent of this program in Java? Or are you wanting to specifically run this script and capture the output in Java? More info please. Commented Feb 7, 2013 at 5:05

2 Answers 2

3

This...

Process p = Runtime.exec("myExeOrShellScript");
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = r.readLine())!=null) {
  // got the output in 'line' do something with it
}
r.close();

whatever you pump out in your shell script with echo will end up in the java program.

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

Comments

1

Check args:

public static void main(String[] args)

Comments

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.