Bash Shell: Find Out Linux / FreeBSD / UNIX System Load Average

by on March 23, 2005 · 8 comments· LAST UPDATED August 8, 2013

in , ,

Yes, I know we can use the uptime command to find out the system load average. The uptime command displays the current time, the length of time the system has been up, the number of users, and the load average of the system over the last 1, 5, and 15 minutes. However, if you try to use the uptime command in script, you know how difficult it is to get correct load average. As the time since the last, reboot moves from minutes, to hours, and an even day after system rebooted. Just type the uptime command:

$ uptime
Sample outputs:

1:09:01  up 29 min,  1 user,  load average: 0.00, 0.00, 0.00

OR
$ uptime
Sample outputs:

2:13AM  up 34 days, 16:15, 36 users, load averages: 1.56, 1.89, 2.06

Traditionally, UNIX administrators used sed and other shell command in scripting to get correct value of load average. Here is my own modified hack to save the time
$ uptime | awk -F'load averages:' '{ print $2 }'
OR better use the following code:
$ uptime | awk -F'[a-z]:' '{ print $2}'
Output taken from my OS X desktop:

 1.24 1.34 1.35

Output taken from my Ubuntu Linux server:

 0.00, 0.01, 0.05

Output taken from my RHEL based server:

 0.24, 0.27, 0.21

Output taken from my FreeBSD based server:

 0.71, 0.71, 0.58

Please note that command works on all variant of UNIX operating systems.

See also

  • See chksysload.bash script to notify admin user if script load crossed certain limit and if so send them an email alert.
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 8 comments… read them below or add one }

1 Stefan August 29, 2007 at 2:18 pm

This information is wrong. The correct command would be:

uptime | awk '{print $10 " " $11 " " $12}'

The above does not work on Solaris 8.

Reply

2 Brad August 7, 2013 at 6:18 pm

This information is wrong.

You can’t just pipe to awk and assume that the 10th field will be the load average.

Because the time field could be 1 or 2 items. “47 days” or “15:45″. Because it’s not consistent you can’t assume the 10th field will be load average.

# uptime
18:17:27 up 47 days, 47 min, 2 users, load average: 0.09, 0.23, 0.42

# uptime | awk ‘{print $10}’
average:

See.

Reply

3 Oo.et.oO September 27, 2007 at 7:52 pm

stefan. his example clearly shows that that just doesn’t work all the time. specifically when uptime is

Reply

4 Szy May 13, 2008 at 1:19 pm

Actually it DOES work. I found that the ‘s’ in ‘averges’ should not be there. Otherwise it works like a charm!

Reply

5 Paresh September 17, 2012 at 5:04 am

Yes, U r right Szy, it works and there should not be ‘s’ in average… It worked fine on AIX. thanks

Reply

6 Chandra December 23, 2008 at 10:30 am

Actually This will work fine, cause there will be different output based on u r last reboot.

# Find the correct field to extract based on how long
# the system has been up, or since the last reboot.
if $(uptime | grep day | grep min >/dev/null)
then
FIELD=11
elif $(uptime | grep day | grep hrs >/dev/null)
then
FIELD=11
elif $(uptime | grep day >/dev/null)
then
FIELD=10
elif $(uptime | grep min >/dev/null)
then
FIELD=9
else
FIELD=8
fi

Reply

7 Yang Yang April 14, 2009 at 4:45 am

Anybody care to explain what these load average figures mean? Is there a unit or is there anything scalely comparable to them? For example, I have:

21:39:33 up 10:45, 5 users, load average: 9.86, 9.68, 10.64

What do 9.86, 9.68 and 10.64 mean here?

Reply

8 Paresh September 17, 2012 at 5:11 am

It means, load averages of CPU in last 1, 5 and 15 mins…

Reply

Leave a Comment

Tagged as: , , , ,

Previous post:

Next post: