Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check 3 groingfiles tail daemon wannabe 1

Status
Not open for further replies.

nabrantes

MIS
Apr 2, 2002
17
PT
Hi there,
I want to check on multiple growing files but I really don't know how to do it.
I know "select()" is somehow related with my question but I cannot figure how to do it with the code bellow ... :(

I have a version of it using File::Tail but I really want to avoid it because I will need to compile it using PAR since the destination server does not have File::Tail and they dont let me install the module. :p

I also want to "uniq"!??! the fetched values. The thing will send emails if trigered but I only want to send 1 from ocurrence every 15 minutes. (thie one I dont know how even with File::Tail :( )

Many thanks
NMA

Code:

open (LOGFILE, $telcofile) or die "can't open $telcofile: $!";
for (;;) {
for ($curpos = tell(LOGFILE); <LOGFILE>; $curpos = tell(LOGFI
+LE)) {
print "Got Line!: $_";
}
sleep 1800;
seek(LOGFILE, $curpos, 0); # seek to where we had been
exit if (stat(LOGFILE))[3] == 0
}
close(LOGFILE) or die "can't close $telcofile:
 
Look into the use lib directive which will allow you install modules without admin rights
--Paul

cigless ...
 
It does not work I allready tried that. Also File::Tail depends on Time::HiRes wich needs to be compiled.

Best Regards.
NMA
 
This does not work entirely correctly. There is a bug, but I do not have time to fix it. I think it will help you go in the direction you need.

Code:
$| = 1;

@previous = ();

open(IN, $ARGV[0]) || die "ERROR ON OPEN FILE\n";
@lastline = (<IN>)[-5 .. -1];
close(IN);

foreach $ll (@lastline) {
     chomp($ll);
     if (scalar(grep(/^${ll}$/, @previous)) == 0) {
          push(@previous,$ll);
     }
}
print STDOUT "INIT SCALAR:", scalar(@previous), "\n";

while (scalar(@previous) > 0) {
     open(IN, $ARGV[0]) || die "ERROR ON OPEN FILE\n";
     @lastline = (<IN>)[-5 .. -1];
     close(IN);

     $count = scalar(@previous) + 1;

     foreach $ll (@lastline) {
          chomp($ll);
          print STDOUT "[$ll]", scalar(@previous), "\n"; sleep(1);
          if (scalar(grep(/^${ll}$/, @previous)) == 0) {
               push(@previous,$ll);
          }
     }

     print STDOUT join("\n", (@previous)[0 .. ($count - 1)]), "\n";

     for ($i = 0; $i <= $count; $i++) {
          shift(@previous);
     }
}

exit(0);

1;


Michael Libeson
 
You got me confused.

But thanks anyway. :)

Since I need to sleep for 15 minutes I do not need to use select() and just use seek&tell with sleep() even if I loose half a line every once and a while.

Best Regards.
NMA
 
use lib does work, and you could probably try commenting out the inclusion of Time::HiRes if your interval is greater than a second. The default time() and sleep() functions should be good enough for whole-number seconds.

Also, be aware that since this sounds like shared hosting of some kind, many are not too keen on long-running processes, even if they're sleeping most of the time. Don't be surprised if your admin hunts you down later. :)

________________________________________
Andrew

I work for a gift card company!
 
* 4 icrf,

"admins are very nice people, unless they hunt you down ..."
--some bloke, quite recently, ectually

--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top