http://www.perlmonks.org?node_id=1023633

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Urgent Help For Perl Issues
by vinoth.ree (Monsignor) on Mar 15, 2013 at 07:48 UTC

    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.

    Example:

    #!/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");
    Update:

    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.

      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");