Score:1

How to monitor a growing log file for specific string and print the line to terminal in realtime?

id flag

For example. I have nohup.out.log file which is growing over time. I want to monitor this file and check if the string test error occurs in this file and print the corresponding lines to terminal or another file such as error.log in real-time. Thanks.

Score:2
cn flag

Go to the directory that has nohup.out.log and do...

/usr/bin/tail -f nohup.out.log | grep "test error" > error.log 

and it will wait for "test error" to occur.

See man tail for more options.

zhengger avatar
id flag
That's what I need. Thanks!
Raffa avatar
jp flag
Might worth noting as well that `-F` will keep trying to open a file if it is inaccessible as opposed to `-f`.
Score:1
vn flag

lnav is a really good logfile explorer for the terminal that features filtering, syntax highlighting etc.

If you have the universe repo enabled, it can be installed with:

sudo apt install lnav

To use it with a specific logfile, run:

lnav /path/to/nohup.out.log

To set up a filter, press Tab, i. Then type the string test error and hit Enter.

Now only log lines with this string is shown.

zhengger avatar
id flag
A useful tool, though I have no root user. Thanks.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.