redirect awk information to stdout

0

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.

Quick Silver

Posted 2013-05-22T02:20:41.653

Reputation: 1

Answers

0

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.

Fred Thomsen

Posted 2013-05-22T02:20:41.653

Reputation: 1 307

Any way I can execute this command in Python?

say e.g

subprocess.call('mpstat -P ALL | awk '{print $4}' >>cpu.txt', shell=True) – Quick Silver – 2013-05-22T04:17:33.583

1Well, you probably need to escape the quotes in the string. – Scott – 2013-05-22T21:18:44.130