I have a black-box system that periodically updates a single-line flag file. This single-line file takes, over the course of the system's life various different values, corresponding to the states of an FSM.E.g. like downloading, validating, posting, etc. At any given point in time the value is different so the software must be opening the flag file, truncating it, and writing the new single-line value.How can I maintain a log of the succession of different values? I was thinking something like tail -f but with the ability to record the different values and with a way that's guaranteed not to mess with the file system when the software is updating of those values. A simple tail -f fails with file truncated after some time.
how to record different values of a flag file
bash
You probably want tail -F (note that it is capitalised), which will retry opening/reading the file if it fails.From man tail:   -f, --follow[={name|descriptor}]          output appended data as the file grows; -f, --follow,           and --follow=descriptor are equivalent   -F     same as --follow=name --retry   --retry          keep trying to open a file even when it is or becomes          inaccessible; useful when following by name, i.e., with          --follow=nameIf your version of tail doesn't have -F (which is equivalent to tail -f=name --retry), you could use inotify, and wait for close_write (inotifywait is part of inotify-tools):file=foowhile inotifywait -qq -e close_write $foo >/dev/null; do    cat $foodone > logtail -F should be preferred if available, because there is a race condition when using inotifywait.