1

I have a java program that runs as a service in linux box. I have shell script file that has the following line to start the program.

$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH" -outfile "$LOG_OUT" -errfile "$LOG_ERR" -pidfile "$PID" $1 $CLASS 

$CLASS_PATH has class path
$CLASS has the name of main class
EXEC="/usr/bin/jsvc"

I can start and stop the service using following commands

  • service myscriptfilename start

  • service myscriptfilename stop

Now I added a new argument to my program called "myflag" . It works fine on windows box . Now I am having difficulty passing the new argument to my program on my linux box using the shell script.

Now I am starting my service as

  • service myscriptfilename start myflag

I can get the value of myflag using $2 in shell script. I am trying to figure out how do I pass that to my program

How can i pass my "myflag" to my program from shell script in the following line?

$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH" -outfile "$LOG_OUT" -errfile "$LOG_ERR" -pidfile "$PID" $1 $CLASS
4
  • Are you asking this? Commented Nov 22, 2015 at 0:48
  • I can get the value of myflag using $2 in shell scriipt . I am trying to figure out how do I pass that to my program? Commented Nov 22, 2015 at 0:58
  • Who knows how your program parses command line arguments. There's no agreed standard, so there could be a million ways. It's your program after all, and you should know better than us... (You didn't even say what's $EXEC, for that matter; maybe it's known to all Java programmers? I'm not sure.) Commented Nov 22, 2015 at 1:04
  • I am looking for args[0].It is working fine in windows box . I am not sure where to pass that argument in linux Commented Nov 22, 2015 at 1:05

1 Answer 1

1

I am considering that $EXEC is java executable, $1 is your JAR, $CLASS is your main class. In this case just append ${@:2} to the end of the line:

$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH" -outfile "$LOG_OUT" -errfile "$LOG_ERR" -pidfile "$PID" $1 $CLASS ${@:2}
Sign up to request clarification or add additional context in comments.

6 Comments

EXEC="/usr/bin/jsvc" and $1=start from the command service myscriptfilename start myflag
Should work nevertheless - it has similar execution options.
@KennerDev, can you investigate which part doesn't work? Have you tried replacing ${@:2} with myflag? There are two places where your parameter may not be passed: service start and jsvc .... Try to determine which of these doesn't work.
It is at jsvc level .It is passing at service start.
@KennerDev, are you retrieving them through DaemonContext ?
|

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.