Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
up vote 2 down vote accepted

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:

share|improve this answer
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 '11 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 '11 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 '11 at 17:21
Ha! I wrote mine after the edit, I didn't see the original answer. – mfinni Jun 1 '11 at 17:21
@mfinni: I forgive you. <3 – prolink007 Jun 1 '11 at 17:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.