Reputation: 29
I listen to stream like this:
cat /dev/ttyS4 | tee -a mylog.log
This correctly outputs data to mylog.log as well as to the terminal. I try to follow the file in another terminal:
tail -f mylog.log
This does not sense an update. If i run ls -la (to see the date of the file), the tail output gets updated. (I can also run 'touch myfile.log'
A couple of years since Linux was my main environment, but I think that this should work without forcing some time update with touch.
I use Ubuntu for Windows.
Upvotes: 2
Views: 1564
Reputation: 157947
tail
, when not writing to a terminal but a pipe or a file, will buffer its output blockwise. Meaning it will output text into the pipe not before the buffer reached a certain size. This buffering is implemented in the gnu libc, see the link below.
On Linux, you can adjust the buffer size and the buffering behaviour at all using the stdbuf
command. The following command for example will make tail output line by line:
stdbuf -oL tail ... | tee ...
Upvotes: 2
Reputation: 29
Update: tail -F
does not work. The file is not rotated and ls -la
(or touch) on the file would lead to the tail -f
working.
I actually resorted to this hack. Just call ls -la
continuously to trigger the system to sense that it has changed. Like this:
while true; do ls -la; sleep 1; done
It is a hack, but it works for me. So it does not actually solve the observed behavior. I think this is a "Linux on windows" problem and not a Linux problem, so I will not spend more time on this issue.
Upvotes: 0
Reputation: 47099
You should use tail -F
(sighs I know ...) as it will detect if the file have been renamed, rotated, etc and if so, open a new file describer for the "new" file.
See man tail
:
$ $ man tail | awk '/-F/' RS=
SYNOPSIS
tail [-F | -f | -r] [-q] [-b number | -c number | -n number] [file ...]
-F The -F option implies the -f option, but tail will also check to
see if the file being followed has been renamed or rotated. The
file is closed and reopened when tail detects that the filename
being read from has a new inode number. The -F option is ignored
if reading from standard input rather than a file.
STANDARDS
The tail utility is expected to be a superset of the IEEE Std 1003.2-1992
(``POSIX.2'') specification. In particular, the -F, -b and -r options
are extensions to that standard.
Upvotes: 2