How to fail gracefully?

J

jdenman

I have a perl script running on a server - it runs the following
command: ssh2 <externalServer> -l <username> \"perl <perlScript>\"")
&& HandleError ("Unable to finish perl script: <perlScript>

where <externalServer> is an external server (located elsewhere),
<username> is the username I'm using to log into the externalServer,
and <perlScript> is the name of the perlScript on the externalServer I
want to run.

The perlScript actually runs fine on the external server, but on my
main server I get the Error: "Unable to finish perl script" printed on
screen, as if it had failed. Watching the progress through a command
line I can see everything as it happens, and it looks just
fine...however ssh2 is not exiting properly so that my original perl
script will continue to run, rather than breaking. I've also tried '||
die("Unable to finish perl script")' and got the same result.

Suggestions?
 
L

Larry

I have a perl script running on a server - it runs the following
command: ssh2 <externalServer> -l <username> \"perl <perlScript>\"")
&& HandleError ("Unable to finish perl script: <perlScript>

Try checking the output of ssh2 to check for failure instead of relying
on the exit code. Alternatively, check the doc. of ssh2 to see why it
would return the code it's returning. Maybe there is something you can
do to make it return the code you want in the situation you want.
 
A

Anno Siegel

I have a perl script running on a server - it runs the following
command: ssh2 <externalServer> -l <username> \"perl <perlScript>\"")
&& HandleError ("Unable to finish perl script: <perlScript>

Why, oh why don't you show the complete command that fails? You
probably have a precedence error in your code, but there's no way to
tell. We'd need to see the complete system() command.

Shrug.

Anno
 
J

Jeff

Found a solution: remove the && HandleError, and check $?

0 = success
2 = problem in script
-1 = failed to execute

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top