Last active
October 9, 2024 16:29
-
-
Save vi/340a2dba88ff14abfa4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Warning: it garbes binary files, use only for text | |
| if [[ -z "$1" || "$1" == "--help" ]]; then | |
| echo "Ouput content of the file being appended to to stdout, continue outputting as more data appears in the file, exit when no processes write to the file for a while." | |
| echo "Usage: cat_and_follow file | something" | |
| exit 1 | |
| fi | |
| F="$1" | |
| THISPID=$$ | |
| ( | |
| lsof -Fa -r 2 "$F" | perl -ne 'INIT{$wd=0;} $wd=0 if /^aw/; if(/^m/) { exit 0 if $wd > 2; ++$wd; }' | |
| kill $THISPID; | |
| )& | |
| exec tail -n +1 -f "$F" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment