Hi All
I'm trying to get a perl script to work that I found in a Cisco Cookbook. My knowledge of perl is very limited so I'm not sure what the issue is and digging around the net is not helping me much.
The script from:
Gives me the following errors:
Anyone notice any blatant errors in that? I'd expect a script in a printed book to work as is
I'm trying to get a perl script to work that I found in a Cisco Cookbook. My knowledge of perl is very limited so I'm not sure what the issue is and digging around the net is not helping me much.
The script from:
Code:
#!/usr/bin/perl
#
# rt.pl -- a script to extract the routing table
# from a router.
#
#Set behavior
$snmpro="public";
#
$x=0;
$snmpwalk="/usr/bin/snmpwalk -v 1 -c $snmpro";
$snmpget="/usr/bin/snmpget -v 1 -c $snmpro";
chomp ($rtr=$ARGV[0]);
if ( $rtr eq "" ) {die "$0: Must specify a router\n"};
print "Destination\tMask\t\tNexthop";
print "\t\t Proto\tInterface\n";
@iftable=\Q$snmpwalk $rtr ifDescr\Q;
for $ifnum (@iftable) {
chomp (($intno, $intname) = split (/ = /, $ifnum));
$intno=~s/.*ifDescr\.//;
$intname=~s/"//gi;
$int{$intno}=$intname;
}
@ipRouteDest=\Q$snmpwalk $rtr ipRouteDest\Q;
@ipRouteMask=\Q$snmpwalk $rtr ipRouteMask\Q;
@ipRouteNextHop=\Q$snmpwalk $rtr ipRouteNextHop\Q;
@ipRouteProto=\Q$snmpwalk $rtr ipRouteProto\Q;
@ipRouteIfIndex=\Q$snmpwalk $rtr ipRouteIfIndex\Q;
#@ipRouteMetric1=\Q$snmpwalk $rtr ipRouteMetric1\Q;
for $intnum (@ipRouteIfIndex) {
chomp (($foo, $int) = split (/= /, $intnum));
chomp (($foo, $dest) = split (/: /, @ipRouteDest[$x]));
chomp (($foo, $mask) = split (/: /, @ipRouteMask[$x]));
chomp (($foo, $nhop) = split (/: /, @ipRouteNextHop[$x]));
chomp (($foo, $prot) = split (/= /, @ipRouteProto[$x]));
#chomp (($foo, $metr) = split (/= /, @ipRouteMetric1[$x]));
$int1 = $int{$int};
if ($int1 eq '') {$int1="Local"};
$prot=~s/\(.*//; $prot=~s/ciscoIgrp/\(e\)igrp/;
printf ("%-15s %-15s %-15s %7s %-25s\n",$dest, $mask, $nhop, $prot, $int1);
$x++
}
Code:
Bareword found where operator expected at ./rt.pl line 16, near "$rtr ifDescr"
(Missing operator before ifDescr?)
Backslash found where operator expected at ./rt.pl line 16, near "ifDescr\"
Bareword found where operator expected at ./rt.pl line 23, near "$rtr ipRouteDest"
(Missing operator before ipRouteDest?)
Backslash found where operator expected at ./rt.pl line 23, near "ipRouteDest\"
Bareword found where operator expected at ./rt.pl line 24, near "$rtr ipRouteMask"
(Missing operator before ipRouteMask?)
Backslash found where operator expected at ./rt.pl line 24, near "ipRouteMask\"
Bareword found where operator expected at ./rt.pl line 25, near "$rtr ipRouteNextHop"
(Missing operator before ipRouteNextHop?)
Backslash found where operator expected at ./rt.pl line 25, near "ipRouteNextHop\"
Bareword found where operator expected at ./rt.pl line 26, near "$rtr ipRouteProto"
(Missing operator before ipRouteProto?)
Backslash found where operator expected at ./rt.pl line 26, near "ipRouteProto\"
Bareword found where operator expected at ./rt.pl line 27, near "$rtr ipRouteIfIndex"
(Missing operator before ipRouteIfIndex?)
Backslash found where operator expected at ./rt.pl line 27, near "ipRouteIfIndex\"
syntax error at ./rt.pl line 16, near "$rtr ifDescr"
syntax error at ./rt.pl line 23, near "$rtr ipRouteDest"
syntax error at ./rt.pl line 24, near "$rtr ipRouteMask"
syntax error at ./rt.pl line 25, near "$rtr ipRouteNextHop"
syntax error at ./rt.pl line 26, near "$rtr ipRouteProto"
syntax error at ./rt.pl line 27, near "$rtr ipRouteIfIndex"
Execution of ./rt.pl aborted due to compilation errors.
Anyone notice any blatant errors in that? I'd expect a script in a printed book to work as is