IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Perl Discussion :

[PERL]- traduire du shell en perl


Sujet :

Langage Perl

  1. #21
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    et en plus sa me tronque les 7 premières lignes de .analyse et donc cela se repercute sur mon .focal:

    .analyse:
    more daemon.log.analyse
    vmonitor ntp
















    on interface wildcard, 0.0.0.0#123
    vmonitor ntpd: Listening on interface wildcard, ::#123
    vmonitor ntpd: Listening on interface lo, 127.0.0.1#123

    je sais pas d'ou cela peut venir car quand je test .analyse avant ce script il est entier et après il est tronqué et .focal par la meme occasion

  2. #22
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    Bizarre est que le script enleve de plus en plus de caractère en début de fichier.analyse plus ce fichier augmente.
    cad: si le fichier .analyse contient 80lignes par ex, les 30 premieres caractères sont effacé et si le fichier passe a 150 c'est carrément 30-40 lignes qui sont tronquées...

    Problème de type??

  3. #23
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    bon je regarde ça
    t'es sous quel OS?

  4. #24
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    machine virtuelle linux et windows

  5. #25
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    bon dis moi si je me trompe, mais moi quand je fais le teste, j'obtiens bien dans le fichier analyse cette ligne uniquement

    vmonitor PREFIX: message de test

    donc es tu sur que tu ne t'es pas mélangé dans la déclaration des variables.
    ici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my ($fichier_analyse, $fichier_conf, $fichier_focal) = ("analyse.txt", "conf.txt", "fichier.focal");
    ?

  6. #26
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par djibril Voir le message
    bon dis moi si je me trompe, mais moi quand je fais le teste, j'obtiens bien dans le fichier analyse cette ligne uniquement

    vmonitor PREFIX: message de test

    donc es tu sur que tu ne t'es pas mélangé dans la déclaration des variables.
    ici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my ($fichier_analyse, $fichier_conf, $fichier_focal) = ("analyse.txt", "conf.txt", "fichier.focal");
    ?
    j ai tout renomé et j ai tout revérifié; j ai enlevé ta première ligne et changé partout les valeurs. je n'ai aucun warning en plus sur des variables non init ou autre. toi tu n'a que cela car ton fichier .analyse est petit mais moi il fait exactement 153 lignes et vu que c'est un fichier log il augmente tout le temps. a chaque foi que j'ai une ligne en plus mon resulat du focal change car une des lignes est tronquées en plus. voilia le programme final que j'ai:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    open (my $fh_analyse, $file_analyse) or die("impossible d'ouvrir le fichier $file_analyse, $!\n");
    	open (my $fh_conf, $conf_file) or die("impossible d'ouvrir le fichier $conf_file, $!\n");
    	my @data_temp;
    	my @file_analyse = <$fh_analyse>;
    	my @conf_file = <$fh_conf>;
     
    	# Lecture fichier analyse
    	foreach my $ligne_analyse (@file_analyse) {
    	 chomp($ligne_analyse);
    	  my $compt = 0;
    	  # Lecture fichier conf
    	  foreach my $ligne_conf (@conf_file) {
    	    chomp($ligne_conf);
    	    # comparaison
    	    if($ligne_analyse =~ /$ligne_conf/i ) {
    	      $compt ++;
    	      last;
    	    }
    	  }
    	  push (@data_temp, $ligne_analyse) if($compt == 0); #mets la ligne du fichier analyse $ligne_analyse dans le tableau @data_temp
    	   $compt = 0;										 # si le compt est à zero.C'est ce tableau qui contiendra les info du nouveau 
    	 }													 #fichier analyse	
    	close($fh_analyse);
    	close($fh_conf);
     
    	open (my $fh_focal, ">$file_focal") or die("impossible d'ecrire dans le fichier $file_focal, $!\n");
    	open (my $fh_analyse2, ">$file_analyse") or die("impossible d'ecrire dans le fichier $file_analyse, $!\n");
    	foreach my $temp (sort @data_temp) {
    	  print {$fh_focal} "$temp\n";
    	  print {$fh_analyse2} "$temp\n";
    	}
    	close($fh_focal);
    	close($fh_analyse2);
     
     	$keep_length=(&nbLignes ($file_focal));
     	#unlink ($file_analyse);
     	unlink ($file_tmp);

  7. #27
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    met ton code sous balise code la prochaine fois pour la lisibilité en utilisant le # de la fenêtre graphique

  8. #28
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    c'est quoi ça?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $keep_length=(&nbLignes ($file_focal));
     	#unlink ($file_analyse);
     	unlink ($file_tmp);
    De plus, j'ai pas le début de ton script!!!

  9. #29
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par djibril Voir le message
    c'est quoi ça?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $keep_length=(&nbLignes ($file_focal));
     	unlink ($file_analyse);
     	unlink ($file_tmp);
    De plus, j'ai pas le début de ton script!!!
    je fait juste une ptite stat de ce qui rentre et ce qui sort dans le filtre donc le keep_lenght.
    puis j'efface les repertoire .tmp et .analyse après avoir rempli le champ .focal

  10. #30
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Je te remet le code un peu abregé.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    #!/usr/bin/perl
    use strict;
    use Carp;
    use warnings;
    # modif à faire ici pour les noms de fichier
    my ($fichier_analyse, $fichier_conf, $fichier_focal) = ("analyse.txt", "conf.txt", "fichier.focal");
    open (my $fh_conf, $fichier_conf) or die("impossible d'ouvrir le fichier $fichier_conf, $!\n");
    close($fh_conf);
    my @data_temp;
    my @fichier_conf = <$fh_conf>;
     
    # Lecture fichier analyse
    open (my $fh_analyse, $fichier_analyse) or die("impossible d'ouvrir le fichier $fichier_analyse, $!\n");
    while(my $ligne_analyse = <$fh_analyse>) {
      chomp($ligne_analyse);
      my $compt = 0;
      # Lecture fichier conf
      foreach my $ligne_conf (@fichier_conf) {
        chomp($ligne_conf);
        # comparaison
        if($ligne_analyse =~ /$ligne_conf/i ) {
          $compt ++;
          last;
        }
      }
      if($compt == 0) {
        push (@data_temp, $ligne_analyse);
      }
    }
    close($fh_analyse);
     
    open (my $fh_focal, ">>$fichier_focal") or die("impossible d'ecrire dans le fichier $fichier_focal, $!\n");
    open (my $fh_analyse2, ">$fichier_analyse") or die("impossible d'ecrire dans le fichier $fichier_analyse, $!\n");
    foreach my $temp (sort @data_temp) {
      print {$fh_focal} "$temp\n";
      print {$fh_analyse2} "$temp\n";
    }
    close($fh_focal);
    close($fh_analyse2);

  11. #31
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    sa me fait pareil c'est bizarre!!!

  12. #32
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    copie colle moi ton code en entier, et joins tes deux fichiers en entier.
    Car chez moi je n'ai pas de soucis.

  13. #33
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    je pourrais le faire demain car j'ai tout au boulot!!

  14. #34
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    .analyse:
    ntpd: Listening on interface eth0, 172.16.15.39#123
    ntpd: Listening on interface eth0, 172.16.15.39#123
    ntpd: Listening on interface lo, 127.0.0.1#123
    ntpd: Listening on interface lo, 127.0.0.1#123
    ntpd: Listening on interface wildcard, 0.0.0.0#123
    ntpd: Listening on interface wildcard, 0.0.0.0#123
    ntpd: Listening on interface wildcard, ::#123
    ntpd: kernel time sync status 0040
    ntpd: ntpd 4.2.0a@1.1190-r Thu Oct 5 04:11:32 EDT 2006 (1)
    ntpd: ntpd 4.2.0a@1.1190-r Thu Oct 5 04:11:32 EDT 2006 (1)
    ntpd: precision = 17.000 usec
    ntpd: precision = 17.000 usec
    ntpd: precision = 18.000 usec
    ntpd: precision = 18.000 usec
    ntpd: precision = 19.000 usecitor ntpd: kernel time sync status 0040
    ntpd: kernel time sync status 0040
    ntpd: kernel time sync status 0040
    choux: patate

    .conf
    ntpd:
    ntpd: kernel time sync
    ntpd: Listening on
    ntpd: ntpd
    ntpd: precision
    ntpd: synchronisation lost
    ntpd: synchronized
    ntpd: time reset


    voila exactement mes fichiers.
    a la fin dans .focal je devarit garder que:
    choux: patate
    alors que le script ne le fait pas

  15. #35
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Bon voilà
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
    #!/usr/bin/perl
    use strict;
    use Carp;
    use warnings;
     
    my ($fichier_analyse, $fichier_conf, $fichier_focal) = ("analyse.txt", "conf.txt", "fichier.focal");
    open (my $fh_conf, $fichier_conf) or die("impossible d'ouvrir le fichier $fichier_conf, $!\n");
     
    my @data_temp;
    my @fichier_conf = <$fh_conf>;
    close($fh_conf);
    # Lecture fichier analyse
    open (my $fh_analyse, $fichier_analyse) or die("impossible d'ouvrir le fichier $fichier_analyse, $!\n");
    while(my $ligne_analyse = <$fh_analyse>) {
      chomp($ligne_analyse);
      my $compt = 0;
      # Lecture fichier conf
      foreach my $ligne_conf (@fichier_conf) {
        chomp($ligne_conf);
        # comparaison
        if($ligne_analyse =~ /$ligne_conf/i ) {
          $compt ++;
          last;
        }
      }
      if($compt == 0) {
        push (@data_temp, $ligne_analyse);
      }
    }
    close($fh_analyse);
     
    open (my $fh_focal, ">>$fichier_focal") or die("impossible d'ecrire dans le fichier $fichier_focal, $!\n");
    open (my $fh_analyse2, ">$fichier_analyse") or die("impossible d'ecrire dans le fichier $fichier_analyse, $!\n");
    foreach my $temp (sort @data_temp) {
      print {$fh_focal} "$temp\n";
      print {$fh_analyse2} "$temp\n";
    }
    close($fh_focal);
    close($fh_analyse2);
    Et il me garde bien ton chou patate

  16. #36
    Candidat au Club
    Inscrit en
    Avril 2008
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 26
    Points : 3
    Points
    3
    Par défaut
    ba maintenan sa marche alors que j'ai rien changé.
    bref c'est très bizarre.
    MERCI!!

  17. #37
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Si ça marche, c'est l'essentiel, surement dû à la précipitation de fin de journée dhier

Discussions similaires

  1. Traduire un script shell en perl
    Par smtp2014 dans le forum Langage
    Réponses: 65
    Dernier message: 26/12/2013, 07h16
  2. Conversion Shell en perl
    Par Leguerinos dans le forum Langage
    Réponses: 2
    Dernier message: 24/07/2007, 11h31
  3. perl dans du shell
    Par chti_juanito dans le forum Langage
    Réponses: 6
    Dernier message: 28/06/2007, 17h28
  4. Executer commande shell depuis perl
    Par Matmal11 dans le forum Langage
    Réponses: 2
    Dernier message: 12/06/2007, 10h35
  5. Shell et perl problème d'interpolation de variable.
    Par Whaouu dans le forum Langage
    Réponses: 7
    Dernier message: 26/10/2005, 17h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo