#!/usr/bin/perl # # lbolt - Print uptime from the lbolt value via Kstat. Solaris 8+. # # 14-Aug-2004 ver 0.90 # # USAGE: lbolt # # SEE ALSO: uptime # # COPYRIGHT: Copyright (c) 2004 Brendan Gregg. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # (http://www.gnu.org/copyleft/gpl.html) # # 14-Aug-2004 Brendan Gregg Created this. use Time::Local; use Sun::Solaris::Kstat; my $Kstat = Sun::Solaris::Kstat->new(); ### Fetch hz ($HZ) = `vmstat -i 2>/dev/null` =~ /clock\s+\d+\s+(\d+)/; $HZ = 100 if $HZ eq ""; # 1000 if hires_tick = 1 ### Fetch lbolt $lbolt = $Kstat->{unix}->{0}->{system_misc}->{lbolt}; ### Calculations $reboot = localtime(timelocal(localtime()) - $lbolt/$HZ); $days = ($lbolt/$HZ) / (60 * 60 * 24); ### Print print "Last booted at: $reboot "; printf("up: %.2f days\n",$days);