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?

shantanuo
  • 3,579
  • 8
  • 49
  • 66

3 Answers3

1
tail -f /var/log/mysql/general.log | tee >(grep Connect > /home/myfile.txt)
quanta
  • 51,413
  • 19
  • 159
  • 217
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.

MikeyB
  • 39,291
  • 10
  • 105
  • 189
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.

Sven
  • 98,649
  • 14
  • 180
  • 226