Class: Keystone::Os::Unix
- Inherits:
-
AbstractOs
- Object
- AbstractOs
- Keystone::Os::Unix
- Defined in:
- lib/keystone/os/unix.rb
Instance Attribute Summary
Attributes inherited from AbstractOs
Instance Method Summary collapse
- #bin_or_usrbin(cmd, option = "") ⇒ Object
- #disk ⇒ Object
- #hostname ⇒ Object
- #ip_address ⇒ Object
- #netstat ⇒ Object
- #process_list ⇒ Object
Methods inherited from AbstractOs
Instance Method Details
#bin_or_usrbin(cmd, option = "") ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/keystone/os/unix.rb', line 17 def bin_or_usrbin(cmd,option="") cmd_option = "#{cmd} #{option}" begin;return `/bin/#{cmd_option}` if File.exists?("/bin/#{cmd}");rescue;end begin;return `/usr/bin/#{cmd_option}` if File.exists?("/usr/bin/#{cmd}");rescue;end begin;return `/sbin/#{cmd_option}` if File.exists?("/sbin/#{cmd}");rescue;end begin;return `/usr/sbin/#{cmd_option}`.chomp;rescue;end end |
#disk ⇒ Object
29 30 31 |
# File 'lib/keystone/os/unix.rb', line 29 def disk bin_or_usrbin("df","-h") end |
#hostname ⇒ Object
25 26 27 |
# File 'lib/keystone/os/unix.rb', line 25 def hostname bin_or_usrbin("hostname") end |
#ip_address ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/keystone/os/unix.rb', line 4 def ip_address ifconfig = `/sbin/ifconfig` ips = [] # TODO mac ifconfig.gsub(/inet addr:(\d+\.\d+\.\d+\.\d+)/){|ip| if $1 != '127.0.0.1' ips << $1 end } return ips end |
#netstat ⇒ Object
37 38 39 40 |
# File 'lib/keystone/os/unix.rb', line 37 def netstat bin_or_usrbin("netstat","-an") `/usr/sbin/netstat -an`.chomp end |
#process_list ⇒ Object
33 34 35 |
# File 'lib/keystone/os/unix.rb', line 33 def process_list bin_or_usrbin("ps","-aux") end |