exit status of remote commands

exit status of remote commands

am 04.10.2007 12:45:09 von Ironhide

Hi,

I want to execute some commands on a remote machine through ssh and
get back their results; would ideally like get back the
1. exit status of the command executed remotely
2. stdout
3. stderr

All this I would like to do inside a perl script and get all of the
above 3 in 3 separate variables.
Can this be done?

p.s.: I have already tried the Net::SSH module; would be helpful if
you guys could suggest me other ways of doing this.

--
IronHide

Re: exit status of remote commands

am 04.10.2007 14:01:28 von Ben Morrow

Quoth Ironhide :
> Hi,
>
> I want to execute some commands on a remote machine through ssh and
> get back their results; would ideally like get back the
> 1. exit status of the command executed remotely
> 2. stdout
> 3. stderr
>
> All this I would like to do inside a perl script and get all of the
> above 3 in 3 separate variables.
> Can this be done?

Well, the obvious way is to run ssh(1) with something like IPC::Run...

> p.s.: I have already tried the Net::SSH module; would be helpful if
> you guys could suggest me other ways of doing this.

What was your problem with Net::SSH?

Ben

Re: exit status of remote commands

am 04.10.2007 14:08:43 von Peter Makholm

Ironhide writes:

> I want to execute some commands on a remote machine through ssh and
> get back their results; would ideally like get back the
> 1. exit status of the command executed remotely
> 2. stdout
> 3. stderr

Try using IPC::Open3;

my($wtr, $rdr, $err);
$pid = open3($wtr, $rdr, $err, 'ssh user@host cmd')

# Work with the filehandles $wtr, $rdr and $err

waitpid($pid);
$exit = $? >> 8;

if $exit is 255 the error might be an error with the ssh command and
not you remote command. Otherwise it should be the exit status of you
remote command.

//Makholm

Re: exit status of remote commands

am 04.10.2007 19:16:16 von xhoster

Ironhide wrote:
> Hi,
>
> I want to execute some commands on a remote machine through ssh and
> get back their results; would ideally like get back the
> 1. exit status of the command executed remotely
> 2. stdout
> 3. stderr
>
> All this I would like to do inside a perl script and get all of the
> above 3 in 3 separate variables.
> Can this be done?
>
> p.s.: I have already tried the Net::SSH module; would be helpful if
> you guys could suggest me other ways of doing this.

What was wrong with Net::SSH? If you don't tell us what you found
unsuitable about Net::SSH, then how are we to know whether some other
module we might recommend suffers the same problem or not?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.