0

たとえば、wget が終了したときにどうすれば tail を kill できますか。

#!/bin/bash
wget http://en.wikipedia.org/wiki/File:Example.jpg &
tail -f example.log
4

1 に答える 1

5

おそらくこれはより良いです-私はそれをテストしていません:

#!/bin/bash
LOGFILE=example.log
> $LOGFILE # truncate log file so tail begins reading at the beginning
tail -f $LOGFILE &
# launch tail and background it
PID=$!
# record the pid of the last command - in this case tail
wget --output-file=$LOGFILE http://en.wikipedia.org/wiki/File:Example.jpg
kill $PID
#launch wget and when finished kill program (tail) with PID

これは、バックグラウンドではテールがコンソールに出力を表示するという事実に基づいています。ただし、これは簡単にリダイレクトできません。

于 2013-11-12T08:20:42.167 に答える