0
I've written this one liner to show MB read/written every 5 seconds.
#!/bin/bash
#iosum.sh
iostat -dmz 5 |\
awk 'BEGIN{rx=wx=0}{if($0 == ""){printf"%.1f %.1f\n",rx,wx}else if($0~/^Device:/){rx=wx=0}else{rx+=$3;wx+=$4}}'
When run from the command line it works perfectly
./iosum.sh
# wait
1.1 0.0
0.0 0.1
0.0 0.0
3.0 3.0
0.0 0.0
# ctrl-c
However, when I try to put the output into a file I get nothing
./iosum.sh > out.txt
# wait
# ctrl-c
cat out.txt
# nothing!
What gives?
Indeed it was a buffering issue. I don't know why it was a buffering issue... but adding
fflush(stdout)
after the printf fixed the issue. – nullUser – 2015-11-07T06:21:56.897I'm actually piping the output of this script to a status bar, so the output NEEDS to be instant. It only makes one line of output every 5 seconds, is this really affecting performance noticeably? – nullUser – 2015-11-07T17:07:14.923
No, you are right. A five second rate is making my performance point moot. It would only hurt with a high throughput. – jlliagre – 2015-11-07T21:31:44.533