exit status of remote commands

I

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.
 
B

Ben Morrow

Quoth Ironhide said:
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
 
P

Peter Makholm

Ironhide said:
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
 
X

xhoster

Ironhide said:
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.
 

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
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top