Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1918 connectés 

  FORUM HardWare.fr
  Programmation
  Perl

  [Perl] Problème de syntaxe

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Perl] Problème de syntaxe

n°1657079
Profil sup​primé
Posté le 12-12-2007 à 11:47:27  answer
 

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.

mood
Publicité
Posté le 12-12-2007 à 11:47:27  profilanswer
 

n°1657082
Elmoricq
Modérateur
Posté le 12-12-2007 à 11:50:43  profilanswer
 

qx// je pense

n°1657087
Profil sup​primé
Posté le 12-12-2007 à 11:57:13  answer
 

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

n°1657089
Elmoricq
Modérateur
Posté le 12-12-2007 à 11:58:38  profilanswer
 


 
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
n°1657094
Profil sup​primé
Posté le 12-12-2007 à 12:02:47  answer
 

OK merci ça marche.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Perl

  [Perl] Problème de syntaxe

 

Sujets relatifs
probleme de droit pour acceder a une page avec site nuked clan[Resolu] Probleme de hauteur de tableau
probleme java beanprobleme sur formulaire
probleme de quotes ![Javascript] Problème entre deux fonctions
Probléme Vb error '429'[G TRouvé] A locker merci modo
Probleme d'affichageProblème affichage du text dans un fichier après OpenTextFile
Plus de sujets relatifs à : [Perl] Problème de syntaxe


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR