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

The following does not work...

tail -f /var/log/mysql/general.log | grep Connect > /home/myfile.txt

If I remove the "-f" switch then I am able to save the output to a text file, but it does not work wile tail is running.

Nor does tee works

tail -f /var/log/mysql/general.log | grep Connect -tee "/home/myfile.txt"


Command provided by quanta does work.

tail -f /var/log/mysql/general.log | tee >(grep Connect > /home/myfile.txt)

But I have to keep the window open. nohup tail -f ... does not seem to work. How do I keep this command running continuously?

share|improve this question
up vote 1 down vote accepted
tail -f /var/log/mysql/general.log | tee >(grep Connect > /home/myfile.txt)
share|improve this answer
Updated my question. will nohup work with this command? – shantanuo Aug 8 '11 at 5:18
No need to use nohup. tail -f will run continuously until you stop it by pressing Ctrl+C. – quanta Aug 8 '11 at 5:47
When I close the putty window, it seems to be killing the process – shantanuo Aug 8 '11 at 5:57
OK. I misunderstand you mean. Read the SvenW's answer. – quanta Aug 8 '11 at 6:17

Actually, it works just fine.

The problem is probably that the output is buffered along each step so you'll need to have a lot of output before it actually gets flushed to the file.

share|improve this answer
You can use grep --line-buffered Connect > /home/myfile.txt. – quanta Aug 8 '11 at 4:44
Right, should have mentioned that. No option for tail though. – MikeyB Aug 8 '11 at 4:49
grep without --line-buffered didn't work on my system. Does it works for you? – quanta Aug 8 '11 at 4:52

About your nohup problem: If you don't want to see the output continuously for some reason, I wouldn't create a separate file with part of the logs (which is essentially what you are doing), but create the extraction on demand with just a grep command.

If you insist on your method, you could use screen or tmux to run your command.

share|improve this answer

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.