The command "w" (/bin/w in Solaris, /usr/bin/w in Linux -- at least Fedora) will give you that information.
The first line of the output should look like:
08:58:53 up 75 days, 18:04, 3 users, load average: 0.03, 0.07, 0.02
or
8:55am up 38 day(s), 1 user, load average: 1.28, 1.37, 1.29
Depending on what you plan to do with it, you may need to parse out specific information. For example, I run the following script every half hour on one of the Solaris boxes I am responsible for:
- #! /bin/perl
-
use strict;
-
-
open IN, "/bin/w |" or die "could not run w to get load average: $!\n";
-
my $line = <IN>;
-
close IN;
-
chomp $line;
-
-
my ($junk,$avgs) = split /load average: /,$line;
-
my ($min,$fivemin,$fifteenmin) = split /, /, $avgs;
-
print scalar localtime(), "\t$min\t$fivemin\t$fifteenmin\n";
(My crontab includes a redirection to append the data to a file.)
HTH,
Paul