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 looking for a way to write the CPU utilization into a text file every 10 seconds.

How might I go about setting this up? I'm running Ubuntu 12.04.

share|improve this question
up vote 1 down vote accepted

CPU utilisation is easy:

From the command line:
while ( sleep 10 ) ; do cat /proc/loadavg >> mylogfile ; done

The sleep command will sleep 10 seconds and than return with the return value 0 (aka success). We abuse that to get a compact while( true ) sleep 10.

/proc/loadavg contains the load avarages of now, over the last 5 minutes, and over the last 15 minutes. If you are logging every 10 seconds then you are only interested in the first value.

Or in a script (using bash).

# Using /bin/sh which is guaranteed to be present on any posix system.
# If you want to add shell specific parts in the script than replace this.
# E.g. if you want to use bash specific stuff then change it to:
# #!/usr/bin/env bash
# Make sure that the shebang is on the first line of the script (no comments above it!)

# While true, pause 10 seconds, then append information to Mylogfile
while ( sleep 10 ) ; do cat /proc/loadavg >> mylogfile ; done

We can add a cat /proc/meminfo to the information we append to the log file. /proc/meminfo is quite extensive and it will log a lot. If you only want to filter on specific memory information then please add that to the post.

The simplest form of that would result in:
while (sleep 10) ; do cat /proc/loadavg /proc/meminfo >> mylogfile ; done).

share|improve this answer
Loadavg doesnt give the cpu utilization. It gives the average job queue length. – Sahil Singh Jan 21 '15 at 18:54
What does give the cpu utilization then? – Greg Bell Dec 25 '15 at 11:37

If you run atop as a daemon, it will log a huge amount of system state data: CPU usage, process list, disk I/O, memory usage and more. You can then step through the data with atop -r [filename].

share|improve this answer

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.