Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Runing Remote Command

by vinoth.ree (Monsignor)
on Apr 11, 2013 at 03:40 UTC ( #1028074=note: print w/replies, xml ) Need Help??


in reply to Runing Remote Command

You can execute commands on remote machines from a Perl script using the Net::SSH::Perl module.

This module allows you to execute a command remotely and receive the STDOUT, STDERR, and exit status of that remote command.

One big advantage of Net::SSH::Perl over other methods is that you can automate the login process, that way you can write fully automated perl scripts, no console interaction is required in order to authenticate in the remote machine.

Ex:

#!/usr/bin/perl use Net::SSH::Perl; my $host = "hostname"; my $user = "user"; my $password = "password"; #-- set up a new connection my $ssh = Net::SSH::Perl->new($host); #-- authenticate $ssh->login($user, $pass); #-- execute the command my($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/$user");

All is well

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028074]
help
Chatterbox?
and the pool shimmers...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2016-12-05 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (72 votes). Check out past polls.