[Perl] Problème de syntaxe

Problème de syntaxe [Perl] - Perl - Programmation

Marsh Posté le 12-12-2007 à 11:47:27    

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 :
  1. #!/usr/bin/perl
  2. #
  3. #         host.pl -- a script to build a detailed host file from
  4. #                    information gathered from a router list.
  5. #
  6. #Set behavour
  7. $workingdir="/home/****";
  8. $snmpro="*****";
  9. #
  10. $rtrlist="$workingdir/RTR_LIST";
  11. $snmpwalk="/usr/bin/snmpwalk -v2c -c $snmpro";
  12. $snmpget="/usr/bin/snmpget -v2c -c $snmpro";
  13. open (RTR, "$rtrlist" ) || die "Can't open $rtrlist file";
  14. open (RESULT, ">$workingdir/RESULT" ) || die "Can't open RESULT file";
  15. while (<RTR> ) {
  16.    chomp($rtr="$_" );
  17.    @ifIndex=\Q$snmpwalk $rtr "ipAdEntIfIndex"\Q;
  18.    @ipAddress=\Q$snmpwalk $rtr ipAdEntAddr\Q;
  19.    $rtr1=\Q$snmpget $rtr .1.3.6.1.4.1.9.2.1.3.0\Q;
  20.    chomp(($foo, $RTR) = split (/"/, $rtr1));
  21.    $arraynum=0;
  22.    for $ifnumber (@ifIndex) {
  23.       chomp(($foo, $ifnum) = split(/= /, $ifnumber));
  24.       $ifDescription=\Q$snmpget $rtr ifName.$ifnum\Q;
  25.       chomp(($foo, $ipaddr) = split(/: /, $ipAddress[$arraynum]));
  26.       chomp(($foo, $ifdes) = split(/= /, $ifDescription));
  27.       $name="$RTR-$ifdes";
  28.       #$name=~s/\//-/;
  29.       if ( $ifdes eq "Lo0" ) { $name=$RTR };
  30.       print RESULT "$ipaddr\t\t$name\n";
  31.       $arraynum++;
  32.    }
  33. }
  34. close(RTR);
  35. 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.

Reply

Marsh Posté le 12-12-2007 à 11:47:27   

Reply

Marsh Posté le 12-12-2007 à 11:50:43    

qx// je pense

Reply

Marsh Posté le 12-12-2007 à 11:57:13    

càd Elmoriq?
 
d'ailleurs dans le code original ligne 17 il n'y a pas de "" pour ipAdEntIfIndex ...

Reply

Marsh Posté le 12-12-2007 à 11:58:38    


 
Documentation PERL : http://perldoc.perl.org
Et plus particulièrement, pour le cas qui t'occupes, la page concernant les opérateurs : http://perldoc.perl.org/perlop.html
 
edit : d'ailleurs, j'viens ainsi d'apprendre que \Q existe bien, mais je ne suis pas sûr de l'utilisation qui en est faite ici... tu es sûr que ce script que tu as pompé fonctionne ? [:opus dei]


Message édité par Elmoricq le 12-12-2007 à 12:06:04
Reply

Marsh Posté le 12-12-2007 à 12:02:47    

OK merci ça marche.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed