1

Here is my scenario:

I have a log file that is being wrote too by an application. The log file is named "alarms.log". I want to tail the file for a certain string and redirect that to a file called alarms.log.test. So i am using the below command.

tail --follow=name alarms.log | grep CEC >> alarms.log.test

Then i tail the file it is being redirected to by using this command:

tail --follow=name alarms.log.test

My problem is this: The file alarms.log.test is not getting anything in the file. I know for a fact that it should be. Because the string is being found. I believe the problem is that the redirect waits for a certain amount of data is read and then flushes to the redirect file, is that the case?

I need it to immediately flush to the file every time something is found. Is there a way to do this?

Thanks

1 Answer 1

3

Can you use the tee command for this?

The tee command is used to store and view (both at the same time) the output of any other command.

Maybe something like the example linked on SuperUser

tail -f alarms.log | egrep --line-buffered 'name' | tee alarms.log.test

Also see: http://linux.101hacks.com/unix/tee-command-examples/

5
  • so my new command would need to look like this: tail --follow=name alarms.log | grep CEC | tee -a alarms.log.test ? If that is the case, it is still not writing it to the file. And i am not seeing anything output to the terminal.
    – prolink007
    Jun 1, 2011 at 17:17
  • Please see the edit and the SuperUser link. Buffering is the problem. Using the --line-buffered switch with egrep works.
    – ewwhite
    Jun 1, 2011 at 17:19
  • @Prolink - you're buffering, that's why nothing is being written. ewwhite's answer had an option for grep to reduce the effects of buffering, you didn't use it and that's why it's still not working. Run his command as he gave it to you and try that.
    – mfinni
    Jun 1, 2011 at 17:21
  • Ha! I wrote mine after the edit, I didn't see the original answer.
    – mfinni
    Jun 1, 2011 at 17:21
  • 1
    @mfinni: I forgive you. <3
    – prolink007
    Jun 1, 2011 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .