The Puppet Labs Issue Tracker has Moved:

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using See the following page for information on filing tickets with JIRA:

Bug #13535

Facter uptime can be wrong or negative on AIX

Added by Malcolm Howe about 4 years ago. Updated over 3 years ago.

Status:ClosedStart date:03/30/2012
Priority:NormalDue date:
Assignee:-% Done:


Target version:1.6.14
Keywords: Affected Facter version:1.6.6

We've Moved!

Ticket tracking is now hosted in JIRA:


On AIX facter can show a negative uptime

uptime => -260 days
uptime_days => -260
uptime_hours => -6219
uptime_seconds => -22385831

This occurs because of the four methods for calculating uptime in facter/util/uptime.rb the only one that can be used on AIX is who -b. But on AIX who -b doesn’t display the year

$ who -b
.        system boot 14 Dec 10:30

so the current year is assumed which in this example results in a negative uptime. A possible solution would be to use the uptime (or equivalently w -u) command which produces similar output on AIX as it does on Linux

$ uptime
10:46AM   up 106 days,  23:18,  3 users,  load average: 0.03, 0.33, 0.53

For example

---      2012-02-28 11:25:38.000000000 +0000
+++ uptime.rb   2012-03-30 11:03:05.000000000 +0100
@@ -4,7 +4,7 @@
module Facter::Util::Uptime
def self.get_uptime_seconds_unix
-     uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b
+     uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_uptime or uptime_who_dash_b
def self.get_uptime_seconds_win
@@ -37,6 +37,20 @@
+   def self.uptime_uptime
+     if output = Facter::Util::Resolution.exec("#{uptime_uptime_cmd} 2>/dev/null")
+       up=0
+       if output =~ /(\d+) days,\s+(\d+):(\d+)/
+           up=86400*$1.to_i + 3600*$2.to_i + 60*$3.to_i
+       elsif output =~ /(\d+):(\d+),/
+           up=3600*$1.to_i + 60*$2.to_i
+       elsif output =~ /(\d+) mins,/
+           up=($1.to_i*60)
+       end
+       up
+     end
+   end
def self.uptime_who_dash_b
if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null")
@@ -57,6 +71,10 @@
def self.uptime_kstat_cmd
'kstat -p unix:::boot_time'
+   end
+   def self.uptime_uptime_cmd
+     'uptime'
def self.uptime_who_cmd

results in the facter output

uptime => 106 days
uptime_days => 106
uptime_hours => 2567
uptime_seconds => 9242280


#1 Updated by Ken Barber about 4 years ago

  • Category set to library
  • Status changed from Unreviewed to Accepted

#2 Updated by Anonymous over 3 years ago

  • Assignee set to Anonymous

I have reproduced this on Solaris 2.6 and facter 1.6.12-rc2 –

myhost[facter-1.6.12-rc2]# uname -s
myhost[facter-1.6.12-rc2]# uname -r
myhost[facter-1.6.12-rc2]# export RUBYLIB=/var/tmp/facter-1.6.12-rc2/lib
myhost[facter-1.6.12-rc2]# ./bin/facter uptime
-106 days

The issue appears on versions of Solaris prior to Solaris 8, when the kstat command was introduced.

It also appears that the AIX implementation of who -b is the standard in all versions of commercial Unix –

Solaris 10 –

$ who -b
   .       system boot  May 31 17:42

HP-UX 11.31 –

$ who -b
   .       system boot  Nov  1 10:43

Tru64 V5.1 –

$ who -b
   .        system boot Jun 18 12:29

I believe Malcolm Howe’s suggestion to introduce a method ‘uptime_uptime’ to run before ‘uptime_who_dash_b’ will fix the problem on all versions of Unix.

#3 Updated by Anonymous over 3 years ago

While looking at the RSpec tests I have noted that who -b didn’t show the year in the file ./spec/fixtures/unit/util/uptime/who_b_boottime that is used in the existing RSpec test either:

$ cat ./spec/fixtures/unit/util/uptime/who_b_boottime
reboot   ~        Aug  1 14:13

I can’t work out what OS that is from – it doesn’t appear to be RHEL, CentOS or Ubuntu.

Meanwhile, the existing RSpec test in spec/unit/util/uptime_spec.rb only works because only the case of one hour in the future is considered:

it "should use 'who -b'" do
  who_b_output_file = my_fixture('who_b_boottime') # Aug 1 14:13
  Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"")
  Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later
  Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60

#4 Updated by Anonymous over 3 years ago

I now know the who_b_boottime output is from a BSD OS, perhaps OS X, which gives me –

$ who -b
reboot   ~        Jul 28 16:34 

#5 Updated by Anonymous over 3 years ago

  • Status changed from Accepted to In Topic Branch Pending Review
  • Branch set to

I have submitted a patch now. See also discussion on puppet developers mailing list under thread ‘who -b etc in facter’s uptime (#13535)’.

#6 Updated by Anonymous over 3 years ago

This is the link to the puppet developers mailing list discussion:–/Zj0P4fHpEUMJ

#7 Updated by Anonymous over 3 years ago

Alex, I’m reviewing this now.

Do you mind if I amend your work (you’ll still be the author, I’ll just be the committer) to rename uptime_uptime to uptime_command?


#8 Updated by Anonymous over 3 years ago

  • Assignee changed from Anonymous to Anonymous

I’m working on this now.


#9 Updated by Anonymous over 3 years ago

  • Branch changed from to

I re-worked a bit of this in my own branch. Alex remains as the author, I’ll be the committer in the history.

#10 Updated by Anonymous over 3 years ago

  • Status changed from In Topic Branch Pending Review to Merged - Pending Release
  • Assignee deleted (Anonymous)


Merged into 1.6.x, 2.x, and master as 8063ffe

Thank you

Alex, thank you very much for this contribution. Sorry it took so long to merge it into the main release branches. Please let me know if you have any questions or concerns.

This fix should be released with Facter 1.6.14 and 2.0.0


#11 Updated by Anonymous over 3 years ago

  • Target version set to 1.6.14

#12 Updated by Anonymous over 3 years ago

Thanks Jeff, and I agree with your amendments to the code.

#13 Updated by Matthaus Owens over 3 years ago

  • Status changed from Merged - Pending Release to Closed

Released in Facter 1.6.14

Also available in: Atom PDF