Server Fault is a question and answer site for system and network administrators. 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 know you can get server load for the past 1, 5, and 15 minutes using commands like "w". However, I would like to automatically retrieve one of those values via a cron job so I can make a note of it in a database and do some analysis and watch the trends. So... I need a command that will output JUST the server load so it can be simply treated as a number for use in my script. Can anyone give me a command that will parse output from a command like "w" and return only the server load value? I'd love to have variations that will return the 5 and 15 minute averages as well. Thanks!

share|improve this question

Each of them, 1, 5 and 15 minute load averages:

cut -f1 -d' ' /proc/loadavg
cut -f2 -d' ' /proc/loadavg
cut -f3 -d' ' /proc/loadavg
share|improve this answer
+1 cut is so handy for this type of thing. – KPWINC Aug 15 '09 at 1:37

Something like this:

CpuLoadAverage=`uptime | awk 'BEGIN { FS=" |, " } { print $11 }'`
echo $CpuLoadAverage

for 5 and 15 minutes, just replace $11 with $12 or $13.

share|improve this answer

Try this:

uptime | perl -e 'while (<>) { m/average:\s(\d.\d+),\s(\d.\d+),\s(\d.\d+)/; print $1; }'

for the 1-minute average, or replace $1 with $2 or $3 for the 5-minute or 15-minute averages respectively.

share|improve this answer
Perl's a little heavy for that, don't you think? – David Pashley Aug 15 '09 at 3:29
Yeah... I wanted to do it with awk or cut but I couldn't remember the syntax. – David Z Aug 15 '09 at 15:54

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.