3

All, I want to extract values from top for plotting purposes. I'm currently using the following command

top -l 0 -s 1  -pid 12345 -stats rsize | awk 'NR%13==0'  

When I run this , I get the expected output. But when I try to redirect the output to a file by running the following:

top -l 0 -s 1  -pid 299 -stats rsize | awk 'NR%13==0' > output.txt  

it doesn't work. What should I do to redirect the output to a file?

I'm on a Mac OSX(Lion)

2
  • 1
    It seems that batch mode (-b) is not implemented on OS X. You could set larger value for -l (say "-l 10"), but you won't be able to see the output until after the script is done, e.g. "tail -f output.txt" won't work for monitoring. – lupincho Feb 19 '12 at 7:45
  • @lupincho: the only problem is awk buffering. – tuergeist Feb 19 '12 at 21:32
2

Your expression is rigth, but be aware that awk buffers its output. So, adding fflush(stdout) to your awk part will help.

top -l 0 -s 1  -pid 299 -stats rsize | awk 'NR%13==0; fflush(stdout)' > output.txt  
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.