Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to gather information for CPU use for all the processors in a text file.

mpstat -P ALL -u 1 | awk '{print $4}' > cpu.txt


mptat -P ALL -u 1 | awk '{print $4}' | tee cpu.txt

Neither of them seems to work when piped.

Any suggestions to get this working.

Much appreciated.

share|improve this question

Try the following:

while true; do
    mpstat -P ALL | awk '{print $4}' >> cpu.txt
    sleep 1

Control-C to stop when you have enough data.

share|improve this answer
Any way I can execute this command in Python? say e.g'mpstat -P ALL | awk '{print $4}' >>cpu.txt', shell=True) – learning May 22 '13 at 4:17
Well, you probably need to escape the quotes in the string. – Scott May 22 '13 at 21:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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