Hello,
I try to make a script. It reads variables from a list (/root/test/list). I have 6 columns but i need only 3: IP, MAC and STATUS column. I need to read from "list" wich IP have status ON and those who are ON to set fixed arp through telnet on my Cisco router.
Here is my script:
proc.pl
#!/usr/bin/perl
my $cisco_host = "xx.xx.xx.xx";
my $cisco_user = "xxx";
my $cisco_pass = "xxx";
use strict;
open(INPUT,"/root/test/list") or die("File not found!\n");
my @input = <INPUT>;
close(INPUT);
my $line;
my $ip;
my $mac;
my %clients;
for $line (@input) {
my ($name,$ip,$mac,$cir,$mir,$status) = split(/\s+/,$line);
print "Processing $name\n";
print "Found $ip , $mac with status $status\n";
$clients{$ip}{status} = $status;
}
require 'csmod.pl';
my $telnet = cisco_Connect($cisco_host,$cisco_user,$cisco_pass) ;
foreach $ip (keys %clients)
{
if($clients{$ip}{status} eq "on") {
$telnet->cmd("arp $ip $mac ARPA");
}
}
#$telnet->cmd("do wr");
$telnet->cmd("exit");
$telnet->cmd("exit");
and here is csmod.pl
use strict;
use Net::Telnet::Cisco;
sub cisco_Connect {
my ($cisco_host,$cisco_user,$cisco_pass,$enable_pass) = @_;
my $telnet = new Net::Telnet::Cisco(Timeout => 10);
$telnet->open($cisco_host);
$telnet->login($cisco_user,$cisco_pass);
$telnet->enable("xxx");
return($telnet);
}
1;
Here is "list" format:
Name 192.168.x.x 00:11:22:33:44:55 2 64 on
When i run the script it gives me the following error:
Use of uninitialized value in concatenation (.) or string at proc.pl line 41.
Line 41 is: $telnet->cmd("arp $ip $mac ARPA");
What i do wrong?
Thank you in advance for your help!
I try to make a script. It reads variables from a list (/root/test/list). I have 6 columns but i need only 3: IP, MAC and STATUS column. I need to read from "list" wich IP have status ON and those who are ON to set fixed arp through telnet on my Cisco router.
Here is my script:
proc.pl
#!/usr/bin/perl
my $cisco_host = "xx.xx.xx.xx";
my $cisco_user = "xxx";
my $cisco_pass = "xxx";
use strict;
open(INPUT,"/root/test/list") or die("File not found!\n");
my @input = <INPUT>;
close(INPUT);
my $line;
my $ip;
my $mac;
my %clients;
for $line (@input) {
my ($name,$ip,$mac,$cir,$mir,$status) = split(/\s+/,$line);
print "Processing $name\n";
print "Found $ip , $mac with status $status\n";
$clients{$ip}{status} = $status;
}
require 'csmod.pl';
my $telnet = cisco_Connect($cisco_host,$cisco_user,$cisco_pass) ;
foreach $ip (keys %clients)
{
if($clients{$ip}{status} eq "on") {
$telnet->cmd("arp $ip $mac ARPA");
}
}
#$telnet->cmd("do wr");
$telnet->cmd("exit");
$telnet->cmd("exit");
and here is csmod.pl
use strict;
use Net::Telnet::Cisco;
sub cisco_Connect {
my ($cisco_host,$cisco_user,$cisco_pass,$enable_pass) = @_;
my $telnet = new Net::Telnet::Cisco(Timeout => 10);
$telnet->open($cisco_host);
$telnet->login($cisco_user,$cisco_pass);
$telnet->enable("xxx");
return($telnet);
}
1;
Here is "list" format:
Name 192.168.x.x 00:11:22:33:44:55 2 64 on
When i run the script it gives me the following error:
Use of uninitialized value in concatenation (.) or string at proc.pl line 41.
Line 41 is: $telnet->cmd("arp $ip $mac ARPA");
What i do wrong?
Thank you in advance for your help!