I have a problem, I'm trying to execute a PERL script allocated on another server. If I execute the command in Linux Shell, the script run correctly. If I execute the script allocating the perl script in the same server of apache Tomcat, runs ok, but when I try to execute the script through ssh by Tomcat, always end with error code 255.
Perl Script:
#!/usr/bin/perl
my $sleeptime = 10;
sleep($sleeptime);
my $argumento=$ARGV[0];
if ( $argumento eq "A" ) {
exit 0;
} else {
exit 192;
}
Now, this is the code in Java file
String command = "ssh root@myserver.com '/usr/bin/perl /var/www/testPerl.pl A'";
process = Runtime.getRuntime().exec(command);
process.waitFor();
if ( process.exitValue() == 0 ) {
System.out.println("Show icon ok");
} else {
System.out.println("Show error");
}
If I change command variable to
String command = "/usr/bin/perl /var/www/testPerl.pl A";
The return code is ok ( 0 or 192 )
Is mandatory to execute remotely, so I can't copy the real PERL to tomcat directory. I did localy just for test.
Did you try the SSH call from the Tomcat server as the tomcat user, eg
ssh root@myserver.com '/usr/bin/perl /var/www/testPerl.pl A'
Try adding -v as ssh argument and capture the output to see if the ssh connection is working. Maybe you're missing RSAAuthentication (key-based instead of password-based) or something else doesn't work as it should.
Try returning some value from Perl for debugging:
print "I'm running (STDOUT)\n";
print STDERR "I'm running (STDERR)\n";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.