The tail -s, –sleep-interval=N option with -f, sleeps for approximately N seconds (default 1.0) between iterations. The tail -s, –sleep-interval=N option with inotify and –pid=P, checks process P at least once every N seconds.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
## Create a script cat <<'EOF'> myscript.sh #!/bin/bash i=1 > myfile while [ $i -le 30 ] do echo "$i" >> myfile sleep 1 ((i++)) done EOF ## execute the script in background and note the pid chmod +x myscript.sh ./myscript.sh & ## PID => [1] 4962 ## tail -s option tail -f -s 20 --pid=4962 myfile ## returns 30 lines and then waits for 20 ## seconds before autometically exit ## execute the script in background and note the pid ./myscript.sh & ## PID => [1] 5001 ## without -s option tail -f --pid=5001 myfile ## returns 30 lines and autometically exit ## default tail -f myfile ## returns 30 lines but does not exit ## press control + c to exist rm my* |