in reply to Re^2: Multiple Device Logon execute the same command
in thread Multiple Device Logon execute the same command

Hi PerlCramps,

Did you read how to execute command in remote machine?

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 = "perlhowto.com"; 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");

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 (or install it if you don't) in order to avoid the slowness problem.


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^4: Multiple Device Logon execute the same command
by PerlCramps (Novice) on Apr 03, 2015 at 12:14 UTC
    I am doing this on a Windows System. I am having problems with Net::SSH::Perl because I could not get the MATH::Pari to install.

      I'd recommend checking out Strawberry Perl. Looking at the latest 32-bit and 64-bit versions available:

      • 32-bit version comes with Net::SSH2, Math::Pari and Math::BigIntGMP modules.
      • 64-bit version comes with Net::SSH2 and Math::BigIntGMP modules.

      I personally have not used any Net::SSH modules, but I believe that Net::SSH2 should be able to do what you're wanting to do. I have to admit that after taking a very quick look at the documentation for Net::SSH2, I'm not sure if I would know how to use it properly. However, I've been meaning to check out Control::CLI, which will use Net::SSH2 for SSH connections. The documentation provides some example code to log into multiple devices and issue commands to multiple devices, which is the basic functionality that you're after. Since the interface looks a lot like the interface of Win32::SerialPort (which I have used before), I think that I personally would have a small learning curve with trying to learn how to use Control::CLI.