Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^2: Watch log for string (tail -f)

by hmb104 (Sexton)
on Oct 12, 2012 at 15:24 UTC ( #998721=note: print w/replies, xml ) Need Help??

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

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); }

Replies are listed 'Best First'.
Re^3: Watch log for string (tail -f)
by live4tech (Sexton) on Oct 14, 2012 at 04:41 UTC

    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
Node Status?
node history
Node Type: note [id://998721]
[karlgoethebier]: hello jedikaiti! something shiny tonight?
[jedikaiti]: It's a very pretty shiney
[jedikaiti]: Shiney!
[karlgoethebier]: very nice!
[shmem]: hm. Can't resolve - weird.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-11-21 18:00 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (308 votes). Check out past polls.