Bonjour
mon script permet de faire un tail -f fichier.log |grep patern >ouput.log
sauf que la redirection vers output.log ne passe pas alors j ai reecrit la roue
un script qui fait un tail -f (repris sur le net)
ajout du critere de recherche de patern
et ecriture du resultat dans un fichier et c'est la ou je ne comprend plus
mon fichier ce cree mais reste vide meme quand le regex est bon cad qu il m afiche la ligne comme dans tail mais pas dans mon fichier
voici mon code:
Code :
- #!/usr/bin/perl -w
- #A Perl version of the unix (tail -f) command
- #written by Nick Pinckernell (see http://illx.org for more details)
- #uses the 'trailing a growing file' from Perl Cookbook
- #NOTE: This script DOES NOT print the last 10 lines of the
- #file like tail does... it just reads a growing file
- #####################################################
- #
- # modify: script is a "tail -f log|grep partern >ouput.log" command
- #
- #
- #
- sub help{
- printf <<__HELP__;
- Usage $0 [Patern] [Log a parser] [Log de destination]
- __HELP__
- }
- my $patern = $ARGV[0];
- unless($patern) {
- help();
- exit 1;
- }
- my $log = $ARGV[1];
- unless($log) {
- help();
- exit 1;
- }
- my $tmpfile = $ARGV[2];
- unless($tmpfile) {
- help();
- exit 1;
- }
- unless( -e $log ) {
- print "The logfile $log you specified doesn't exist, exiting...\n";
- exit 1;
- }
- use IO::Handle;
- open(LOG, "$log" ) or die "Can't open $log: $!\n";
- open(TMPFILE,">$tmpfile" ) or die "Can't open $tmpfile: $!\n";
- #seek to end of file
- seek(LOG, 0, 2);
- #and start watching it from there
- for(;;) {
- while(<LOG> ) {
- if (/$patern/) {
- print "$_";
- print TMPFILE "$_";
- }
- }
- #change sleep for faster or slower updating
- sleep 1;
- LOG->clearerr();
- }
- close(LOG);
- close(TMPFILE);
|
si quelqu un a une idée
a oui aussi je doit faire arreter le tail au bout d un certain delay
ca doit ce mettre quelque part dans ma boucle for mais je vois pas comment
merci a vous