The scene is like, yesterday I need to check some api bug. So I logged into the log server. I opened up a tmux session, so I can reconnect to my work later.
I typed in tail -f data_log | grep keyword
to debug. But didn't work it out at that moment. So I decided to keep this tmux session for later and closed the terminal pane.
And today my colleague told me my tmux session with tail -f data_log | grep keyword
running has caused a hard disk exhaustion on that log server. Which makes me feel ashamed, self-blamed and confused.
As tail -f
opens its own stdout file descriptor and redirect the newly added content of data_log to the terminal screen.
Can this stdout file descriptor receive infinite amount of data?
Where does this file descriptor store this large amount of data? Is there a real file to store them?
Does tmux have anything to do with this issue?
If tmux has nothing to do with this issue, if I opened a terminal running tail -f my_log
, and used crontab to add 1 byte to my_log per second, does it mean that every second 2 bytes will be stored on my disk?(1 for tail and 1 for crontab task)?
-F
will close the old fd and open the freshly rotated file, avoiding this issue – A.B Jun 06 '18 at 04:55-F same as --follow=name --retry
, and explanation for retry iskeep trying to open a file even when it is or becomes inaccessible; useful when following by name, i.e., with --follow=name
, the description is confusing to me. So without-F
, tail -f will read the deleted file, willlogrotate
open a new file with the same name? Where does system writing the newly added log? Cantail -f
show the newly added log? – Zen Jun 06 '18 at 06:03With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end. This default behavior is not desirable when you really want to track the actual name of the file, not the file descriptor (e.g., log rotation). Use --follow=name in that case. That causes tail to track the named file in a way that accommodates renaming, removal and creation.
.--follow=name
<=>-F
– A.B Jun 06 '18 at 06:18-f
vs-F
. – Olorin Jun 06 '18 at 07:35