Coffee & Beer

Rantings and Ravings of the technical sort

Born on Dates for Systems

Wrote this fact a while ago but though it was worth throwing up here.

We’ve got a lot of systems. Our inventory is slightly lacking, and many were build a long long time ago. Many time we’ve found ourselves asking “When the hell was X system built?” or maybe “rebuilt”. Thus, for RHEL/CentOS systems at least, we can get a fact for that:

(born_on.rb) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/ruby
require 'facter'

begin
          Facter.operatingsystem
rescue
          Facter.loadfacts()
end
os = Facter.value("operatingsystem")
if os.match(/CentOS|RedHat/) then
  unless  `rpm -q --last basesystem`.empty?
      Facter.add("born_on") do
          setcode do
              date = `rpm -q --qf '%{INSTALLTIME}' basesystem`
              born_on = `date --date=@#{date} +%F`.chomp
              born_on
          end
      end
  end
end

Giving us:

1
born_on => 2011-11-03

Comments