Search code examples
javabashshellsshnohup

Run two java programs in a bash script after ssh


In my script I SSHed a host and tried to run two java programs. The first java program runs with nohup and & at the end. After that I try to run another java program but it gives syntax error. I guess it has something to do with the &. I do not want to ssh again.

ssh $host "nohup java -cp daemon.jar:. runtime.daemon.MPJDaemon >>/logs/$host-wrapper.log 2>&1 &;java Health"

It gives bash: -c: line 0: syntax error near unexpected token `;

Any ideas


Solution

  • In bash, & implies semicolon (;), so you don't really need that semicolon after the ampersand

    From http://hacktux.com/man/bash

    If a command is terminated by the control operator &, the shell executes the command in the background in a subshell.