scott at sonic.net
Thu Dec 16 23:31:06 PST 2004
On Wed, Dec 15, 2004 at 11:48:22AM -0800, Walter Hansen wrote:
> Hmmm. Been a while since I played with shell scripts. I probably should
> take the class some time.
> I got:
> top -b -d 30 | egrep 'Cpu(s)|load average|PID|nusd'
> to work but when I try to redirect output to a file it doesn't:
> top -b -d 30 | egrep 'Cpu(s)|load average|PID|nusd' > toplog.txt
> and it also didn't work when I did this:
> nohup top -b -d 30 | egrep 'Cpu(s)|load average|PID|nusd' > toplog2.txt &
> or when I put the above command in a file made it +x and then ran it.
> Although in both of the last cases I could see the top process running.
> Hmmm. I guess I'd better go kill those processes.....
I think this is egrep detecting output is a file and buffering.
nohup top -b -d 30 \
| egrep --line-buffered 'Cpu(s)|load average|PID|swapper' \
> toplog2.txt &
p.s. the grep(1) man page calls it "--line-buffering", but is incorrect --
use "egrep --help" to see the real option.
More information about the talk