Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get linux system information in Ruby

How do I get the software/hardware information of a linux system (this has to work for Fedora, Ubuntu etc) in Ruby?

like image 235
jrg Avatar asked Oct 24 '11 22:10

jrg


3 Answers

The wonderful people behind Chef, have an excellent gem called Ohai https://github.com/opscode/ohai that returns system info such as OS, kernel, specs, fqdn, disks, space, memory, users, interfaces, ssh keys etc. as a hash. It is quite complete and very good. It also installs a command line binary (also called ohai).

like image 147
Erik Hinton Avatar answered Oct 03 '22 10:10

Erik Hinton


You could try the sysinfo gem. If that doesn't work you might be able to try making a system call, parse the output, and then call the relevant command to get further information.

For example, on OS X, uname -a gives me the following output, which then allows me to know what other distro-specific commands are likely available.

$ uname -a
Darwin [machine-name].local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64
like image 24
jefflunt Avatar answered Oct 03 '22 11:10

jefflunt


You could try the sys-uname gem, which provides some access to OS information. That guy also has a few other gems for other system info, like cpu, user groups, etc.

like image 39
kafuchau Avatar answered Oct 03 '22 11:10

kafuchau