From: David Ashmore Date: 2006-11-17T06:06:58+09:00 Subject: Re: finding which OS? Luke Kanies wrote: > 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 > > I use this: myhome = ENV['HOME'] path = 'load path: '+$:.to_s script = 'Script location = '+Dir.pwd+$0+' pid id '+$$.to_s rubyinfo = 'OS = '+RUBY_PLATFORM+' and Ruby version = '+VERSION puts 'Below is script location' puts script puts 'Below is rubyinfo' puts rubyinfo puts 'Below is load path' puts path puts ' My Shell enviroment = ' + ENV['SHELL'] puts ' My Home dir = ' + ENV['HOME'] puts ' My username = ' + ENV['USER'] -- Regards Dave Ashmore SOHO IT Solutions llc 1934 S. Delaware Dr. Easton, PA 18042 610-258-7128 http://callsohoit.com Sometimes I can be reached via Skype as djash34 Disclaimer: The below quote is randomly generated and I may or may not agree with the quote. ################################################################ HELP! MY TYPEWRITER IS BROKEN! -- E. E. CUMMINGS ################################################################