cancel
Showing results for 
Search instead for 
Did you mean: 

Tail and Grep

Brahnda A. Eleazar
Occasional Advisor

Tail and Grep

Peace all,

I was trying to use tail and grep for log monitoring.
Such as this:
tail -f my.log | grep error

It's working in Linux but doesn't seem so in HP-UX 11.23.

Any help?

Thanks,
=adley=
11 REPLIES
Suraj K Sankari
Honored Contributor

Re: Tail and Grep

Hi,
What is the output you are getting ?

Suraj
Nido
Trusted Contributor

Re: Tail and Grep

Hi,

>>>>tail -f my.log | grep error
Its working for me on both Linux and HPUX 11.23,11.11.

Anyway tail -f option is ignored when reading from a pipe.
Instead of "-f" option you can put a sleep argument in your script for the desired time.

Cheers!!



" Let Villagers Be Happy!! "
Venkatesh BL
Honored Contributor

Re: Tail and Grep

Looks like with '-f' option waits for further input even after the EOF is reached(see manpage). So, it will show you the pattern, but, won't terminate.

What is the difference you are seeing? Can you post both the outputs?
Brahnda A. Eleazar
Occasional Advisor

Re: Tail and Grep

Peace all,

Thanks for the inputs.

The problem is there is no output.
It simply hung after I pressed ENTER (it's been like this for 5 minutes almost) :)

Well, I asked this because I wanted to monitor IPMON logs.
But, I think I'll just reroute the ipmon logs to a separate file instead. :)

Thanks,
=adley=
Venkatesh BL
Honored Contributor

Re: Tail and Grep

May be there is no 'error' thus far!
Brahnda A. Eleazar
Occasional Advisor

Re: Tail and Grep

Peace,

I thought about that.
The thing is, I did try to simulate an error attempt.

For example, if the ipf rule is this:
pass in quick on lan8 proto tcp from 10.192.x.y to any port = NNNN keep state
block in log quick on lan8 proto tcp from any to any port = NNNN keep state

I tried attempting to the same port from, say, 10.192.x.z, I did get rejected by ipf. But no logs of the blocking.

But nevermind, I have re-routed the logs to another file instead of syslog.log; so I can tail there instead easily. :)

Really appreciate everyone's help!

Thanks,
=adley=
Suraj K Sankari
Honored Contributor

Re: Tail and Grep

Hi Again,

>>tail -f my.log | grep error

will open your my.log and waiting for any line which is having error insert into the my.log file.

if your my.log file will not getting any error string then you will not getting any error.

Suraj
Aneesh Mohan
Honored Contributor

Re: Tail and Grep

see..


# echo "error $(date)" >> /tmp/pv

# tail -f /tmp/pv |grep error
error Thu Jun 18 10:00:49 UTC 2009


Aneesh
john korterman
Honored Contributor

Re: Tail and Grep

Hi,

perhaps you should try a non-case sensitive search:

# tail -f my.log | grep -i error

regards,
John K.
it would be nice if you always got a second chance
Brahnda A. Eleazar
Occasional Advisor

Re: Tail and Grep

Peace all,

Turns out you're all correct.
It did work in HP-UX 11.23.
The problem for me, perhaps, was that I'm trying to tail and grep from a very big text file and it took quite a long time to finish (I didn't bother waiting though).

I tried the exact command to a much smaller text file and it worked! :)

Sorry for the false alarm.

Thanks a lot,
=adley=
Brahnda A. Eleazar
Occasional Advisor

Re: Tail and Grep

Thread closed.

Thanks everyone.