Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Watch log for string (tail -f)

by live4tech (Sexton)
on Oct 12, 2012 at 11:01 UTC ( #998659=note: print w/replies, xml ) Need Help??

in reply to Watch log for string (tail -f)

I think the tail -f will continue until interrupted as other posters pointed out.

I was wondering also why you used {$path} in the line my $logFile = "{$path}/DHCPD.log.{$currentDate}" rather than the variable you created, {$logPath}?

Is this a typo?

Replies are listed 'Best First'.
Re^2: Watch log for string (tail -f)
by hmb104 (Sexton) on Oct 12, 2012 at 15:24 UTC

    That was a typo and I have fxed it. I'm still not getting any idea abou7t how to do this, and how to break out the tail -f?

    This is what I got so far:

    #!/NMS/perl/ACTIVE/bin/perl -w use warnings; use strict; #variables my $currentDate = `date +%Y%m%d`; my $logPath = "/logs"; my $logFile = "$logPath/log.$currentDate"; my $ipaddress = $ARGV[0]; my @tail = `tail -f $logFile | grep $ipaddress`; #print "Log file: $logFile\n"; #print "IP address: $ipaddress\n"; # script begins if (@tail) { my @lines = $tail[0 - 2]; print @lines; exit(0); } else { print "not found"; exit(1); }

      I think you will need to use the file handle with the while loop as the other posters have suggested. Have you tried this?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://998659]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2023-12-07 14:14 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (32 votes). Check out past polls.