1

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"

update

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?

3 Answers 3

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

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.

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

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.

You must log in to answer this question.

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