ok, Appologies to all for not having included the whole thing, but here...
the script is for collecting customer interface stats using snmp, and
I need to destinguish what type of router the customer connects to in
order to have the right MIB. It runs with a cfg file which I have
included, which calls a file containing entries like the following...
router1=1.1.1.1|cisco
router2=2.2.2.2|juniper
unknown=0.0.0.0|unknown
I've also included most of the main script to show more of what I'm
doing to hopefully clear up and issues about lists/hashs (but that might
still be the problem...) Any info appreciated...
Thanks
Andrew
#!/usr/bin/perl
#
#
$config_file = "configure/monitor.cfg";
# print "Initializing ...\n";
&initialize;
# print "Generating interface-table ...\n";
&mkinterface;
sub initialize
{
#
# Reading configuration file
#
open (CFG,"$config_file") || die "Can't find configuration file
($config_file)\n";
while (<CFG>)
{
chomp;
($var,$val) = split("=");
$cfg{$var} = $val;
}
close (CFG);
}
#
# Reading router database
#
open (CFG,"$cfg{ROUTERS}") || die "Can't open router file $cfg{ROUTERS}\n";
while (<CFG>)
{
chomp;
($name,$address) = split("=");
$router_tables{$name} = $address;
}
close (CFG);
sub mkinterface
{
open (SH,">$cfg{MKINTERFACE}") || die "Can't create $cfg{MKINTERFACE}\n";
print SH "#!/bin/sh\n";
print SH "# Auto-generated script: ",`date`;
print SH "cat /dev/null > $cfg{INTERFACETABLE}\n";
print SH "for i in ";
foreach $i (sort keys %router_tables)
{
next if ($i =~ "unknown");
($router_table{i},$router_type{$i}) = split(/\|/, $router_tables{i});
if ($router_table{i} ne "") {
print SH "\"$router_table{$i}\" ";
}
else {
print SH "\"$router_tables{$i}\" ";
}
}
print SH "\ndo\n";
print SH "\t$cfg{SNMPINDEX} \$i $cfg{COMMUNITY} >> $cfg{INTERFACETABLE}\n";
print SH "done\n";
close(SH);
}
COMMUNITY=@OU812+
ROUTERS=/home/andrewr/statsprogramme/tarball/monitor/configure/routers
INTERFACETABLE=/home/andrewr/statsprogramme/tarball/monds/cf/apr-interface-table
MKINTERFACE=/home/andrewr/statsprogramme/tarball/monitor/configure/mkinterface
SNMPINDEX=/home/andrewr/statsprogramme/tarball/monitor/configure/snmpindex