0

I've a script. It looks like this:

#!/bin/sh
watch -n300 java -jar myapp.jar > out.log &
mkdir aaa
echo "App accesa"

When I call this myscript.sh from my app in Java with the Ganymed library it doesn't execute the watch statement but the 'aaa' folder has been created. My statement in java is

Session sess = conn.openSession();
String command = "cd /root/;./myscript.sh";            
System.out.println(command);
sess.execCommand(command);

I can't understand the problem why if I run the myscript.sh script from console it works fine.

Thanks in advance

Davide
  • 1,931
  • 2
  • 19
  • 39
  • Technically, you have a shell script, not a bash script. A bash script would begin with `#!/bin/bash`. How do you run `myscript.sh` from the command line? What if you remove the shebang? Try `sh myscript.sh` vs `bash myscript.sh`. Do you get the same result? – reynoldsnlp Oct 13 '15 at 18:33
  • From command line I run this script by this command: ./myscript.sh I already tried with sh myscript.sh, but the result is the same. By console it's all ok, but with ganymed the watch statement command doesn't work – Davide Oct 13 '15 at 18:35
  • What if you remove the shebang and then try with `bash myscript.sh` and `sh myscript.sh`? – reynoldsnlp Oct 13 '15 at 18:37
  • Always the same. By console it's all ok, but from my app that statement doesn't work – Davide Oct 13 '15 at 18:47
  • But if I remove this 'watch -n300' it works also by my app but only one time – Davide Oct 13 '15 at 18:49

0 Answers0