D.2. A Perl Version of Uptime#!/usr/bin/perl -w # # uptime - Perl Kstat version of uptime. Solaris 8+. # # This program fetches similar statistics to the /usr/bin/uptime command, # as a demonstation of the Perl Kstat module. # # USAGE: uptime # use strict; use Sun::Solaris::Kstat; ### Create Kstat object my $Kstat = Sun::Solaris::Kstat->new(); ### Fetch load averages my $load1 = $Kstat->{unix}->{0}->{system_misc}->{avenrun_1min}; my $load5 = $Kstat->{unix}->{0}->{system_misc}->{avenrun_5min}; my $load15 = $Kstat->{unix}->{0}->{system_misc}->{avenrun_15min}; ### Fetch boot time my $boot = $Kstat->{unix}->{0}->{system_misc}->{boot_time}; ### Processing $load1 /= 256; $load5 /= 256; $load15 /= 256; my $days = (time() - $boot) / (60 * 60 * 24); ### Print output print scalar localtime(); printf ", up %.2f days", $days ; printf ", load averages: %.2f, %.2f, %.2f\n", $load1, $load5, $load15; |