-
-
Save d630/f14991af78721d7afbd79ef9eff321ad to your computer and use it in GitHub Desktop.
bash: match PATTERN in tail -f and kill background process
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
# execute it with source | |
unalias tail | |
echo 1 > /tmp/TEST_LOG; | |
sleep 100 & | |
pid_bg=$! | |
i=0 | |
while | |
IFS= read -r | |
do | |
((i++, pid_tail = i == 1 ? $REPLY : pid_tail)) | |
[[ $REPLY == PATTERN ]] && kill $pid_bg $pid_tail; | |
done < <( | |
tail -f /tmp/TEST_LOG & | |
echo $! | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment