Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

best method in perl to execute command on remote server and fetch its output

by janasec (Sexton)
on May 24, 2015 at 13:02 UTC ( [id://1127583]=perlquestion: print w/replies, xml ) Need Help??

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

hi , I need to execute perl commands on remote systems and fetch the output,what is it which is convenient ssh,rsh or TELNET.

I need to run several commands in a order and gather the output on several servers

I also need to save the output of each command executed

  • Comment on best method in perl to execute command on remote server and fetch its output

Replies are listed 'Best First'.
Re: best method in perl to execute command on remote server and fetch its output
by moritz (Cardinal) on May 24, 2015 at 13:09 UTC

    Regardless of the programming language you use, and regardless of questions of convenience, you should use ssh. In contrast to both rsh and telnet, it can be secure.

    On the perl side of things, Net::OpenSSH has a pretty good reputation. It's ->capture method lets you retrieve the output of a remote command, so it seems to fit your requirements.

      thanks for the quick reply

      please can you simple give a working example using the module Net::OpenSSH ,I checked the perldoc for the same but could not find a solution to ssh with username and password and run the command and gather output

      Thanks in advance

Re: best method in perl to execute command on remote server and fetch its output
by thanos1983 (Parson) on May 24, 2015 at 15:01 UTC

    Hello

    I think the answer(s) to all your question(s) lies on this question:Best module to execute administrator commands on external operating systems (Linux). Do not be afraid of the Linux part if you are running another OS all the modules can be executed on all OS.

    I had the same problem some time ago and I tested all possible ways on my question and I posted all possible solutions/ limitations that I found. So my final and easiest decision is to work with Net::OpenSSH::Parallel where you can execute multiple commands, in parallel. Even sudo commands in parallel and capture the output.

    Hope this helps.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found