Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

exit status of a remote program

by lucarey (Initiate)
on Jun 17, 2001 at 02:41 UTC ( [id://89110]=perlquestion: print w/replies, xml ) Need Help??

lucarey has asked for the wisdom of the Perl Monks concerning the following question:

I'm writting a backups script that runs from the general purpose server to 6 workstations.
#!/usr/local/bin/perl $machine=$ARGV[0]; %runt=( "local" , "yes", "tape" , "/dev/nrmt0h", "dev1" , "/dev/rz0a", "dev2" , "/dev/rz0g", "dev3" , "/dev/vol/rootdg/us_striped", "dump", "/usr/sbin/dump 5bdsuf 64 61000 6100"); $status=system("rsh $machine mt -f $$machine{tape} online");
$status will be 0 unless the remote machine is down. I was wondering if there was a way to get the return status of the "mt -f" command. Is there a better way/module for doing this?

Replies are listed 'Best First'.
Re: exit status of a remote program
by btrott (Parson) on Jun 17, 2001 at 06:28 UTC
    If you can use ssh instead of rsh (which maybe you should be doing anyway :), you can use Net::SSH::Perl, which has a method to execute a command remotely and get back the stdout, stderr, and exit status.
    use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new($host); $ssh->login; my($out, $err, $exit) = $ssh->cmd($cmd);
    Exit status of remote command is in $exit.
Re: exit status of a remote program
by kschwab (Vicar) on Jun 17, 2001 at 05:02 UTC
    There probably is a module, but a cheesy hack goes something like so:
    $status=`rsh $machine somecommand >> /dev/null 2>&1;echo $?`; $rshstatus=$?;
    This is only useful if you don't need the regular output from "somecommand". Note that it just has the remote shell output it's last command status variable. If the remote shell is csh, you'd have to echo $status instead of $?.
Re: exit status of a remote program
by TeKk9 (Scribe) on Jun 17, 2001 at 05:09 UTC
    I recall doing something like this before, however you might want to have a look at the O'Reilly book "Programming Perl". I think there was a section on using exec|system and evaluating the return values.
    my @args = ("/usr/bin/mt", "-f", "$$machine{tape}", "online"); my $status = system(@args) / 256; if( $status < 0 || $status > 0 ) { &error_code; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://89110]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-16 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found