Monitoring a file until a string is found
Problem
I am using to monitor a log file that is being actively written to. When a certain string is written to the log file, I want to quit the monitoring, and continue with the rest of my script. Currently I am using: When the string is found, quits as expected, but I need to find a way to make the quit too so that the script can continue.
Error Output
tail -f logfile.log | grep -m 1 "Server Started"
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix for: Monitoring a file until a string is found
Here is a simple one-liner. It doesn't need bash-specific or non-POSIX tricks, or even a named pipe. All you really need is to decouple the termination of from . That way, once ends, the script can continue even if hasn't ended yet. So this simple method will get you there: will block until it has found the string, whereupon it will exit. By making run from it's own sub-shell, we can place it in the background so it runs independently. Meanwhile, the main shell is free to continue execution of …
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix