I have a question.
I need to do a bash script command that show me CPU usage and stamp in an external txt file.
Have some idea? Thank all so much!
I have a question.
I need to do a bash script command that show me CPU usage and stamp in an external txt file.
Have some idea? Thank all so much!
You can use sysstat
as suggested in the comments or stick with (probably installed already) top
. Example from my system (you can of course grep out a specific field if needed):
$ top -bn 1 | sed -n '3p'
%Cpu(s): 16.4 us, 3.1 sy, 0.0 ni, 79.0 id, 1.3 wa, 0.0 hi, 0.2 si, 0.0 st
You can add the timestamp with date
:
$ date
Thu Nov 1 19:46:15 MSK 2012
The top version and sysstat never worked for me. This did:
ps -A -o pcpu | tail -n+2 | paste -sd+ | bc