in reply to Multiple Device Logon execute the same command

Hi PerlCramps,

So you want to write a perl script which reads the list of server name from a file and execute a set of commands in remote server.

Why dn't you try yourself writing a sample script and execute? Here I am giving you the hints to try or search in google.

1.How to read and write a text file in perl?

2.How to execute a command in remote host and extract the output?

So if you could try writing script and if you face any problem please post as, lot of monks are here to help you.


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

Replies are listed 'Best First'.
Re^2: Multiple Device Logon execute the same command
by PerlCramps (Novice) on Mar 26, 2015 at 17:35 UTC
    Vinoth.ree I toke your advise and tried to get a little smart with perl. I created this script but I am have a problem getting the result part to read the contents of the varible assigned. Please tell me what I am doing wrong; also if there is a better way I am all ears. Thanks SCRIPT
    #!/usr/bin/perl -w use strict; use warnings; main (@ARGV); sub main { # This array contains the list of hosts my @host = ("ajsfdevbcs11", "ajsfdevbcs12"); my $i; for($i = 0; $host[$i]; $i++) { # message ($host[$i]); } # This is the logon ID my $user = "tsasa067"; # message ($user); # This is the logon password my $security = 'F@therL0^eMe'; # message ($security); # These are the commands I would like to run my @cmd = ("switchname", "chassisshow", "switchstatusshow", "switc +hshow"); my $j; for($j = 0; $cmd[$j]; $j++) { # message ($cmd[$j]); } my @results = 'plink -ssh -pw = $security -l = $user $host'; print $results[0]; } sub message { my $m = shift or return; print ("$m\n"); } sub error { my $e = shift || 'unkown error'; print("$0: $e\n"); exit 0; }
      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...
        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.
Re^2: Multiple Device Logon execute the same command
by PerlCramps (Novice) on Mar 06, 2015 at 19:50 UTC
    thank you I will work on the information you listed.