Search code examples
shelltail

Quit tail -f command from script


I am doing tail -f -n 10 test.log .

I want this tail command to terminate once a signal file is created at some location .

say finish.txt. If finish.txt file exists then stop tailing or else continue


Solution

  • That should take care of the problem:

    signal_file=some/location/finish.txt
    
    tail -f -n 10 test.log &
    
    until [ -e "$signal_file" ]; do sleep 1; done
    
    kill %