Reputation: 11
I am trying to execute a shell script (that makes use of a perl script and other shell scripts) from java program, however I am not successful, here is what I tried:
On the Linux server, in a folder test1/testJava the following scripts are available:
Here is what I try from java:
try {
ConnBean cb = new ConnBean("xx.yyy.zz.p", "user","passme");
ssh = SSHExec.getInstance(cb);
CustomTask ct1 = new ExecShellScript("/test1/testJava", "./decode24.sh", "arg1");
ssh.connect();
net.neoremind.sshxcute.core.Result res = ssh.exec(ct1);
}catch......
Result after execution:
error message:
./decode.sh[17]: shadow.pl: not found [No such file or directory]
./decode.sh[21]: fram.sh: not found [No such file or directory]
Upvotes: 0
Views: 92
Reputation: 20002
Let decode.sh find out the directory it is in (see bash solution) and use the path for calling the others.
Upvotes: 0
Reputation: 13696
The error comes from your decode.sh
script. It cannot find the shadow.pl
and fram.sh
scripts that it executes. Probably because the CWD or path is not set to the script dir when you run the script.
The most robust way to solve it is to change your decode.sh
script to use absolute paths to the shadow.pl
and fram.sh
scripts. That way you can execute decode.sh
from any directory.
If you use bash, check out this question for a neat way to resolve the absolute directory to the scripts to avoid hard coding the path.
Upvotes: 1