Class: SystemCall

Inherits:
Object
  • Object
show all
Defined in:
lib/system_call.rb

Defined Under Namespace

Classes: IspUnityException

Class Method Summary collapse

Class Method Details

.execute(commands = []) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/system_call.rb', line 3

def execute(commands=[])
  begin
    if commands.is_a?(Array)
      commands.each {|cmd| `#{cmd}`} 
    else
      `#{commands}`
    end
    return true
  rescue Exception => e
    IspUnityLog.debug("#{e}")
    IspUnityLog.error(I18n.t('system_call.execute.error'))
    IspUnityException.new(I18n.t('system_call.execute.error'))
  end
end

.get_ip(interface) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/system_call.rb', line 18

def get_ip(interface)
  return '127.0.0.1' if ENV['GEM_ENV'] == 'test'
  begin
    result = `/sbin/ifconfig #{interface}`
    ip = /inet addr:(?<ip>(\d+[.]){3}\d+)/.match(result)
    ip = ip[0].split(':')[1] if ip
  rescue Exception => e
    IspUnityLog.debug("#{e}")
    IspUnityLog.error(I18n.t('system_call.execute.error'))
    IspUnityException.new(I18n.t('system_call.execute.error'))
  end
end