Created
July 30, 2015 02:10
-
-
Save gongo/284190a40c1fc7b00f71 to your computer and use it in GitHub Desktop.
バックグラウンド実行中のプログラムが特定の文字列を出力するのを待って kill する系
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 | |
PIPEFILE="pipefile" | |
BKPID="" | |
BK=`cat << 'EOL' | |
for i in $(seq 1 30) ; do | |
echo $i | |
sleep 1 | |
done | |
EOL` | |
[[ -p "$PIPEFILE" ]] || mkfifo "$PIPEFILE" | |
bash -c "$BK" > "$PIPEFILE" & BKPID="$!" | |
echo "$BKPID" | |
while read LINE ; do | |
echo $LINE | |
if [[ "$LINE" == "8" ]] ; then | |
kill -s TERM "$BKPID" | |
break | |
fi | |
done < "$PIPEFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
出力結果