Operating System - Linux
1828308 Members
3455 Online
109975 Solutions
New Discussion

Re: perl, ssh, status of remote command

 
SOLVED
Go to solution
John Kittel
Trusted Contributor

perl, ssh, status of remote command

I'm writing a perl program, using the system function to call ssh to run a program on another system. I'm trying to get the exit status back from the remote command. It seems to work, except that the values are weird. An exit status of 0 comes back as a 0, but an exit status of 1 comes back as 256, an exit status of 2 comes back as 512, an exit status of 10 comes back as 2560.

The perl program is running on a firewall which is a BSD derivative, and the remote system is HP-UX 11i. They have somewhat different versions of ssh. The firewall version is a bit old.

Is the problem wih the status values likely due to the ssh versions ?, or am I doing something wrong in my perl program ?

The relevant part of my test program is like this:

$status = system("/usr/contrib/bin/ssh user\@host /whatever/myscript");

print "t1.pl status is: $status\n";


Thanks.

- John
2 REPLIES 2
Mel Burslan
Honored Contributor
Solution

Re: perl, ssh, status of remote command

John,

I think perl's exit status processing has some sinister detail that I could not quite figure out myself but here it is from my perl bookshelf cd, the function detail page for "system" function, which has an example that may help you. HTH...

(attached as txt to preserve code formatting)
________________________________
UNIX because I majored in cryptology...
John Kittel
Trusted Contributor

Re: perl, ssh, status of remote command

Thanks Mel. That's good enough for me.

That page from the manual says in part, "The return value is the exit status of the program as returned by the wait(2) call. To get the actual exit value, divide by 256. (The lower 8 bits are set if the process died from a signal.) See exec."

... and the somewhat more complete explanaion comes from, where else?, the Programming Perl book, which I'd read (but forgotten about) some time ago, and which says in part, " the lower byte has something else in it... the lowest 7 bits indicate the signal number that killed the process ( if any), and the 8th bit indicates whether the process dumped core".


- John