Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Urgent Help For Perl Issues

by vinoth.ree (Monsignor)
on Mar 15, 2013 at 07:48 UTC ( #1023636=note: print w/replies, xml ) Need Help??

in reply to Urgent Help For Perl Issues

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.


#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; my $host = ""; my $user = ""; my $password = ""; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("your command");

Execution of Net::SSH::Perl commands can be quite slow if you don't have the Math::BigInt::GMP module; so be sure that you have that module installed in order to avoid the slowness problem. Make sure that in both the Linux servers ssh enabled and server listens on port number 22.

Replies are listed 'Best First'.
Re^2: Urgent Help For Perl Issues
by arvindninestars (Initiate) on Mar 15, 2013 at 08:23 UTC
    Hi Vinoth, Great its working fine. But one thing if i login into server its landing into default path.But if i need to untar into different path after landing, what can i do? Example : My landing path /home/systems after that need to change "testing" directory and untar. Please help!!!!

      If you choose to use this familiarise yourself with ssh, and the Net::SSH::Perl documentation, the README shows you where sample/tutorial scripts live within the distribution.

      Just use the cd command with your path and navigate to your path and do untar

      my($stdout, $stderr, $exit) = $ssh->cmd("cd $path"); ($stdout, $stderr, $exit) = $ssh->cmd("untar tar.gz");
        Hi Vinoth,
        my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $password); my($stdout, $stderr, $exit) = $ssh->cmd("cd testing"); ($stdout, $stderr, $exit) = $ssh->cmd("unzip");
        This one i used. But file unzipped in home directory only not unzipped inside testing folder.. Any Worng....

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023636]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2018-02-17 23:23 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (250 votes). Check out past polls.