Bash Shell Find out Linux / FreeBSD / UNIX system load average

by on March 23, 2005 · 7 comments· Last updated August 29, 2007

Yes, I know we can use uptime command to find out system load average. If you try to use 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 time uptime
$ uptime
Output:
1:09:01 up 29 min, 1 user, load average: 0.00, 0.00, 0.00

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

Traditionally many UNIX administrators used sed and other shell command in scripting (over 5-10 line of code) to get correct value of load average. Here is my own modified hack to save time
$ uptime | awk -F'load averages:' '{ print $2 }'
Output:

0.01, 0.01, 0.00

Note that command works on all variant of UNIX.

Shell Script

=> See chksysload.bash script to notify admin user if script load crossed certain limit and if so send them an email alert.



You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 7 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 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

3 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

4 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

5 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

6 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

7 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

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 6 + 2 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Tagged as: , , , ,

Previous post:

Next post: