tail -f
みたいに流しながら見たいんだけど、色んなコマンドが出力をバッファしちゃうので、困ったときはそのコマンドにバッファしないオプションが無いか探すのがオヌヌメ。
man command
-> bufferとかで検索
grep
--line-buffered
Use line buffering, it can be a performance penality.
$ iostat -x 1 | grep --line-buffered 'sda'
awk
fflush([file]) Flush any buffers associated with the open output file or pipe file. If file is missing, then standard output is flushed. If file
is the null string, then all open output files and pipes have their buffers flushed.
$ vmstat 1 | awk '{print $1}{fflush()}'
mysql
? --unbuffered, -n
Flush the buffer after each query.
$ mysql -n -uroot -e "SQL"
※あまり使う場面が思いつかなかったですが、少なくともfork & execでSTDOUTとか継続して使おうとした時に必要でした。
perl
普通にprint STDOUT "hogehoge"
とかするとteeに噛ませるとバッファされる。
$| = 1;
$ hoge.pl | tee /tmp/log
This comment has been minimized.
riywo commentedMar 17, 2011
あんま関係ないけど、ifstatをawkでやるとこんな感じ、ってのでteeでログ吐く場合はfflushしてあげないとSTDOUTに出てこない。