Sha256: 1c67597101c3e606ef3de4796abc5845b4a544fb57d2afd996deea81816f51d9

Contents?: true

Size: 1.02 KB

Versions: 11

Compression:

Stored size: 1.02 KB

Contents

module Keystone
  module Os
    class Unix < AbstractOs
      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

      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

      def hostname
        bin_or_usrbin("hostname")
      end

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

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

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

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
kanamei-keystone-0.0.18 lib/keystone/os/unix.rb
kanamei-keystone-0.0.19 lib/keystone/os/unix.rb
kanamei-keystone-0.0.20 lib/keystone/os/unix.rb
kanamei-keystone-0.0.21 lib/keystone/os/unix.rb
kanamei-keystone-0.0.22 lib/keystone/os/unix.rb
kanamei-keystone-0.0.23 lib/keystone/os/unix.rb
kanamei-keystone-0.0.24 lib/keystone/os/unix.rb
kanamei-keystone-0.0.25 lib/keystone/os/unix.rb
kanamei-keystone-0.0.26 lib/keystone/os/unix.rb
kanamei-keystone-0.0.27 lib/keystone/os/unix.rb
keystone-0.0.29 lib/keystone/os/unix.rb