1

I have a log file that text is appended to during the program run. I want to know when a specific string was appended to the end of the file.

All the solutions given here: Monitoring a file until a string is found and here: https://stackoverflow.com/questions/25959870/how-to-wait-till-a-particular-line-appears-in-a-file work, but only on Ubuntu.

I'm trying to do the same thing on Centos 7 and it doesn't seem to end the command.

some things I tried that work in Ubuntu but not in Centos 7:

( tail -f -n0 logfile & ) | grep -q "database start"

tail -n0 -f logfile | sed '/database start/ q'

No idea why it would not work on CentOS 7 but on Ubuntu it does work. I prefer to use a single command instead of sleeping x and grep again, because the line should be outputted multiple times in the file and I want only the one since I started checking the file

I did check the log file and the line did appear, but none of the commands stopped.

DavidPostill
  • 162,382
Codo
  • 13

1 Answers1

0

Is it possible the "database start" is perhaps written as "Database start"?
The default grep may not ignore a change of case, requiring grep -i for doing that.

The following might be safer syntax :

grep -q "database start" <(tail -f logfile)

Reference : How to wait till a particular line appears in a file.

harrymc
  • 498,455