nixCraft Poll

Topics

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

Posted by Vivek Gite [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.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Stefan Says:

    This information is wrong. The correct command would be:

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

    The above does not work on Solaris 8.

  2. Oo.et.oO Says:

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

  3. Szy Says:

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

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.