Created
June 30, 2014 09:08
-
-
Save vi/340a2dba88ff14abfa4f to your computer and use it in GitHub Desktop.
This file contains 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 | |
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