を実行する場合tail -f error.log
、ファイルに3秒間何も追加されなかった後、プログラムで改行を挿入するにはどうすればよいですか?
(明らかに、1つの改行が追加されたら、他の行のテキストがログファイルに追加されるまで、他の改行を追加しないでください)
たとえば、これらの行はerror.logに追加されます。
foo
bar
boo [[wait 4 seconds]]
2far
2foo
2bar
2boo [[wait 40 seconds]]
2far
これはコンソールの出力になります:
foo
bar
boo
2far
2foo
2bar
2boo
2far
たとえば、(ファイル全体をダンプしているように、tail -f
コメントを外さない限り、ここで)いつでも手動で実装できます。seek()
tail -n +1 -f
perl
perl -e '
$| = 1;
# seek STDIN, 0, 2; # uncomment if you want to skip the text that is
# already there. Or if using the ksh93 shell, add
# a <((EOF)) after < your-file
while (1) {
if ($_ = <STDIN>) {
print; $t = 0
} else {
print "\n" if $t == 3;
# and a line of "-"s after 10 seconds:
print "-" x 72 . "\n" if $t == 10;
sleep 1;
$t++;
}
}' < your-file
または、3秒間入力がない場合tail -f
は、テーリングを実行しperl
て改行を挿入します。
tail -f file | perl -pe 'BEGIN{$SIG{ALRM} = sub {print "\n"}} alarm 3'
これらは、出力自体が遅くならないことを前提としています(出力がアクティブに読み取られていないパイプに送られる場合など)。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加