vasanth.easyrider has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 gi +ven 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 => $Ele +prompt)) { 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 exces +sive-flow-trap"); #String => $string,Prompt => $ +match); print "output is = @output\n"; @output = $t->cmd(String => $string,Prompt => $matc +h,Errmode => die); #String => $string,Prompt => +$match); print "output is = @output\n"; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Telnet not capturing output
by hippo (Archbishop) on Feb 23, 2018 at 08:52 UTC | |
by vasanth.easyrider (Acolyte) on Feb 23, 2018 at 09:12 UTC | |
|
Re: Telnet Error - Vasanth
by thanos1983 (Parson) on Feb 23, 2018 at 09:42 UTC | |
by vasanth.easyrider (Acolyte) on Feb 23, 2018 at 09:52 UTC | |
by hippo (Archbishop) on Feb 23, 2018 at 09:59 UTC | |
by vasanth.easyrider (Acolyte) on Feb 23, 2018 at 10:04 UTC | |
by thanos1983 (Parson) on Feb 23, 2018 at 11:48 UTC |