This should be simple but I am missing something, need some help. My requirement is to read the log file via tail to get latest logs, grep Download Config & Copying all files of and write it in MyOwnLogFile.log but I want this to stop as soon as .myworkisdone file appears in /usr/local/FOLDER/ One thing is sure that .myworkisdone will be generated at the last when all logs are done… but the script just continues to read the log file and never comes out of it, even if the file is created.
while [[ ! -e /usr/local/FOLDER/.myworkisdone ]];
do
sudo tail -f -n0 /var/log/server22.log | while read line; do echo "$line" | grep -e 'Downloading Config’ -e ‘Copying all files of' ; done >> /var/tmp/MyOwnLogFile.log
done
I also tried until
instead of while to check the file but still the script cant break the spell of reading the log file.
Thank you in advance.
tail -f
will follow the file indefinitely, the condition in the outerwhile
is pretty much checked only once. If you want to terminate thetail
when the.myworkisdone
file appears, you'll have to arrange for it to be killed explicitly. But that sounds a bit awkward. Would it be possible to to first wait for the file to appear, and then grep through the complete log file, withouttail -f
? – ilkkachu May 01 '21 at 10:17