Class: Keystone::Os::Unix

Inherits:
AbstractOs show all
Defined in:
lib/keystone/os/unix.rb

Direct Known Subclasses

Darwin, Linux

Instance Attribute Summary

Attributes inherited from AbstractOs

#version

Instance Method Summary collapse

Methods inherited from AbstractOs

#dump

Instance Method Details

#bin_or_usrbin(cmd, option = "") ⇒ Object



18
19
20
21
22
23
24
# File 'lib/keystone/os/unix.rb', line 18

def bin_or_usrbin(cmd,option="")
  cmd_option = "#{cmd} #{option}"
  begin;return `/bin/#{cmd_option}`.chomp if File.exists?("/bin/#{cmd}");rescue;end
  begin;return `/usr/bin/#{cmd_option}`.chomp if File.exists?("/usr/bin/#{cmd}");rescue;end
  begin;return `/sbin/#{cmd_option}`.chomp if File.exists?("/sbin/#{cmd}");rescue;end
  begin;return `/usr/sbin/#{cmd_option}`.chomp;rescue;end
end

#diskObject



30
31
32
# File 'lib/keystone/os/unix.rb', line 30

def disk
  bin_or_usrbin("df","-h")
end

#hostnameObject



26
27
28
# File 'lib/keystone/os/unix.rb', line 26

def hostname
  bin_or_usrbin("hostname")
end

#ip_addressObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/keystone/os/unix.rb', line 5

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

#netstatObject



38
39
40
41
# File 'lib/keystone/os/unix.rb', line 38

def netstat
  bin_or_usrbin("netstat","-an")
  `/usr/sbin/netstat -an`.chomp
end

#process_listObject



34
35
36
# File 'lib/keystone/os/unix.rb', line 34

def process_list
  bin_or_usrbin("ps","-aux")
end