Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

Try the following:

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

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 subprocess.call('mpstat -P ALL | awk '{print $4}' >>cpu.txt', shell=True) –  learning May 22 '13 at 4:17
1  
Well, you probably need to escape the quotes in the string. –  Scott May 22 '13 at 21:18

Your Answer

 
discard

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.