Skip to content

Instantly share code, notes, and snippets.

@d630
Last active September 21, 2016 20:54
Show Gist options
  • Save d630/f14991af78721d7afbd79ef9eff321ad to your computer and use it in GitHub Desktop.
Save d630/f14991af78721d7afbd79ef9eff321ad to your computer and use it in GitHub Desktop.
bash: match PATTERN in tail -f and kill background process
# 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