问题
How do I get the software/hardware information of a linux system (this has to work for Fedora, Ubuntu etc) in Ruby?
回答1:
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).
回答2:
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
回答3:
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.
回答4:
You question isn't very specific, but have a look at the sysinfo gem.
来源:https://stackoverflow.com/questions/7882664/how-do-i-get-linux-system-information-in-ruby