Profil supprimé | Bonjour j'ai récupéré ce script qui via SNMP récupére les adresses IP et Label des interfaces de routeurs Cisco.
Code :
- #!/usr/bin/perl
- #
- # host.pl -- a script to build a detailed host file from
- # information gathered from a router list.
- #
- #Set behavour
- $workingdir="/home/****";
- $snmpro="*****";
- #
- $rtrlist="$workingdir/RTR_LIST";
- $snmpwalk="/usr/bin/snmpwalk -v2c -c $snmpro";
- $snmpget="/usr/bin/snmpget -v2c -c $snmpro";
- open (RTR, "$rtrlist" ) || die "Can't open $rtrlist file";
- open (RESULT, ">$workingdir/RESULT" ) || die "Can't open RESULT file";
- while (<RTR> ) {
- chomp($rtr="$_" );
- @ifIndex=\Q$snmpwalk $rtr "ipAdEntIfIndex"\Q;
- @ipAddress=\Q$snmpwalk $rtr ipAdEntAddr\Q;
- $rtr1=\Q$snmpget $rtr .1.3.6.1.4.1.9.2.1.3.0\Q;
- chomp(($foo, $RTR) = split (/"/, $rtr1));
- $arraynum=0;
- for $ifnumber (@ifIndex) {
- chomp(($foo, $ifnum) = split(/= /, $ifnumber));
- $ifDescription=\Q$snmpget $rtr ifName.$ifnum\Q;
- chomp(($foo, $ipaddr) = split(/: /, $ipAddress[$arraynum]));
- chomp(($foo, $ifdes) = split(/= /, $ifDescription));
- $name="$RTR-$ifdes";
- #$name=~s/\//-/;
- if ( $ifdes eq "Lo0" ) { $name=$RTR };
- print RESULT "$ipaddr\t\t$name\n";
- $arraynum++;
- }
- }
- close(RTR);
- close(RESULT);
|
Voici le résultat lors de l'éxecution du script qui montre que la syntaxe \Q pose pb (qui d'ailleurs je ne connaissais pas l'existence de ce paramétre) :
String found where operator expected at host.pl line 17, near "$rtr "ipAdEntIfIndex""
(Missing operator before "ipAdEntIfIndex"?)
Backslash found where operator expected at host.pl line 17, near ""ipAdEntIfIndex"\"
(Missing operator before \?)
Bareword found where operator expected at host.pl line 18, near "$rtr ipAdEntAddr"
(Missing operator before ipAdEntAddr?)
Backslash found where operator expected at host.pl line 18, near "ipAdEntAddr\"
Backslash found where operator expected at host.pl line 19, near "1.3.6.1.4.1.9.2.1.3.0\"
(Missing operator before \?)
Bareword found where operator expected at host.pl line 24, near "$rtr ifName"
(Missing operator before ifName?)
Backslash found where operator expected at host.pl line 24, near "$ifnum\"
(Missing operator before \?)
syntax error at host.pl line 17, near "$rtr "ipAdEntIfIndex""
syntax error at host.pl line 18, near "$rtr ipAdEntAddr"
syntax error at host.pl line 19, near "1.3.6.1.4.1.9.2.1.3.0\"
syntax error at host.pl line 24, near "$rtr ifName"
Execution of host.pl aborted due to compilation errors.
Meric d'avance pour votre aide. |