#!/usr/bin/perl use strict; use warnings; use DBI; use Switch; use Net::Telnet(); my $file = $ARGV[0] or die "Need to get CSV file on the command line\n"; #reading the hostname, IP address and credentials in a csv file given as an argument my $sum = 0; my ($host,$hostname,$username, $passwd, $Eleprompt,$t,$string,$match,$output,@output); open(my $data, '<', $file) or die "Could not open '$file' $!\n"; my $i=1; while(my $line = <$data>) { chomp $line; my @fields = split "," , $line; $host = $fields[0]; $hostname = $fields[1]; $username = $fields[2]; $passwd = $fields[3]; $Eleprompt = $fields[4]; print "IP of device $i = $host\n"; print "Hostname of device $i = $hostname\n"; print "Username of device $i = $username\n"; print "password of device $i = $passwd\n"; print "login prompt of device $i = $Eleprompt\n"; eval { if($t = new Net::Telnet (Timeout => 20, Prompt => $Eleprompt)) { print "Got the expected prompt for $hostname\n"; } print "connection status = $t\n"; $t->open($host); my $CS = $t->login($username, $passwd); print "login status = $CS\n"; $string = "show isis neighbors"; $match = $Eleprompt; @output = $t->cmd("admin show environment leds"); #String => $string,Prompt => $match); print "output is = @output\n"; @output = $t->cmd("show running-config lpts punt excessive-flow-trap"); #String => $string,Prompt => $match); print "output is = @output\n"; @output = $t->cmd(String => $string,Prompt => $match,Errmode => die); #String => $string,Prompt => $match); print "output is = @output\n"; };