From: Luke Kanies Date: 2006-11-17T05:31:36+09:00 Subject: Re: finding which OS? On Nov 16, 2006, at 3:17 AM, dc wrote: > hi - > > is there a way to find which OS Ruby is running on? Facter[1] does this and much more: luke@midden(0) $ irb irb(main):001:0> require 'facter' => true irb(main):002:0> Facter.value(:operatingsystem) => "Darwin" irb(main):003:0> Facter.macaddress => "00:0a:95:96:5f:64" irb(main):004:0> Facter.to_hash.each do |p, v| next if p =~ /key/; puts "%s => %s" % [p, v] end kernel => Darwin rubysitedir => /usr/lib/ruby/site_ruby/1.8 operatingsystemrelease => 8.8.0 hardwaremodel => Power Macintosh ipaddress => 192.168.0.4 kernelrelease => 8.8.0 fqdn => midden.madstop.com ps => ps -auxwww domain => madstop.com rubyversion => 1.8.2 puppetversion => 0.20.1 hostname => midden facterversion => 1.3.3 operatingsystem => Darwin macaddress => 00:0a:95:96:5f:64 home => /Users/luke Note that Facter distinguishes the kernel from the operatingsystem; you'll correctly get 'Debian' or 'Fedora' as your operating system, for instance, not 'Linux'. Also, FWIW, Facter is pretty darn easy to extend: Facter.add(:myfact) do setcode { ...find your data } end 1 - http://reductivelabs.com/projects/facter -- Luke Kanies http://madstop.com | http://reductivelabs.com | 615-594-8199