CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Perl: connect to network devices, run set of commands



Oct 21, 2013, 10:36 AM

Post #1 of 1 (961 views)
Perl: connect to network devices, run set of commands Can't Post

I am trying to write a script for my own use that will allow me to connect to network devices, then run a set of commands.
I start with a list of ips in a text file. Each ip is on its own line.
I start with a second file of commands. Each command on one line.
for illustration .. the cmd.txt file exists and has the following commands resident

sh ver
sh run

use strict;
use warnings;
use Net::OpenSSH;
my $user = 'popeye';
my $password = 'thesailorman';
use vars qw ($cmd $host @HOSTS @CMDS); #
open (SEED, 'ip.txt') or die ("Missing list of ips.");
close SEED;
open (CMD, 'cmds.txt') or die ("Missing list of commands.");
@CMDS = <CMD>;
close CMD;
foreach $host (@HOSTS) {
chomp $host;
print "$host\n";
my $ssh = Net::OpenSSH->new(host=>"$host", user=>"$user", port=>22, password=>"$password");
foreach $cmd (@CMDS) {
chomp $cmd;
print "$cmd\n";



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives