1

I´ve written a small batchjob that should kill and start a process on a linux host. Killing the process works fine but executing the shellscript to start the job again dos not.

plink -v -pw password root@192.168.1.63 "pgrep -f jobname | xargs kill"
plink -v -pw password root@192.168.1.63 "cd /data/server && /bin/bash runsrv.sh"

So the second row shows no error but also no job is startet and I´ve no idea why.

EDIT 1: Here is the content of the runsrv.sh fil:

JBOSS_CLASSPATH=.
export JBOSS_CLASSPATH
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=utf8 -Xms3072M  -Xmx3072M -XX:MaxPermSize=512m -XX:+AggressiveOpts -XX:+DoEscapeAnalysis"
export JAVA_OPTS
nohup ../../bin/run.sh -c idx -b 192.168.1.63 > log/serverstdout.log 2>&1 &

Thanks for any hint in advance!

Michael
  • 2,966
  • 3
  • 30
  • 33
  • What does the `runsrv.sh` do? I'm pretty sure your syntax is just right for *"Start shell script via plink"* - So your problem is specific to your shell script. So please do not generalize. – Martin Prikryl Oct 17 '16 at 08:32
  • If you add `echo starting` at the start of the shell script, do you get the "starting" in Plink? – Martin Prikryl Oct 17 '16 at 08:36
  • Prepend `start "" /WAIT` to each line... – aschipfl Oct 17 '16 at 17:47
  • runsrv.sh works... it´s the main startjob for our server and is in use for a couple of years now. Also If I enter both lines directly on the host it works as expected... – Michael Oct 19 '16 at 06:47
  • start /WAIT was a good idea - thanks for that. Unfortunatelly this is not the reason. Also if I only run the second command via plink the service is not started. I will add the content of the .sh file... – Michael Oct 19 '16 at 06:55
  • What's in the `serverstdout.log` after you run the script? – Martin Prikryl Oct 19 '16 at 07:21
  • @aschipfl The `start "" /wait` has no effect here. A batch file always waits for a command to finish. – Martin Prikryl Oct 19 '16 at 07:23
  • And again: If you add `echo starting` at the start of the shell script, do you get the "starting" in Plink? – Martin Prikryl Oct 19 '16 at 07:24
  • In general, yes, @MartinPrikryl, but not always, depending on the architecture of the application: for example type `winword.exe` into a command prompt window and you will see that you can continue in the console during Word is still open; then type `start "" /WAIT winword.exe` and you will find that you need to close Word in order to be able to continue working in the console... – aschipfl Oct 19 '16 at 09:16
  • 1
    @aschipfl Yes, on command-line, but not in a batch file. [Batch file always waits for an application to close](http://stackoverflow.com/q/19381082/850848) - And even if not, the Plink is a console application. Even command-line always waits for a console application to finish. – Martin Prikryl Oct 19 '16 at 09:30
  • So I learned something new, @MartinPrikryl, I did not know there is a difference in console and batch files; thank you! – aschipfl Oct 19 '16 at 09:38

0 Answers0