Module: HelperClasses::System
Instance Attribute Summary
Attributes included from DPuts
#log_file, #mutex, #show_time, #silent, #terminal_width
Instance Method Summary
collapse
Methods included from DPuts
ddputs, dlog_msg, dp, dputs, dputs_func, dputs_getcaller, dputs_out, dputs_unfunc, log_msg
Instance Method Details
#exists?(cmd) ⇒ Boolean
20
21
22
23
|
# File 'lib/helperclasses/system.rb', line 20
def exists?(cmd)
dputs(3) { "Exist command --#{cmd}--?" }
run_bool("which #{cmd} > /dev/null 2>&1")
end
|
#iptables(*args) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/helperclasses/system.rb', line 36
def iptables(*args)
if !@iptables_cmd
if System.exists?('iptables')
@iptables_cmd = 'iptables'
@iptables_wait = (System.run_str('iptables --help') =~ /\s-w\s/) ? '-w' : ''
else
@iptables_cmd = ''
end
end
if @iptables_cmd != ''
System.run_str("#{@iptables_cmd} #{@iptables_wait} #{args.join(' ')}")
else
return ''
end
end
|
#rescue_all(msg = 'Error') ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/helperclasses/system.rb', line 25
def rescue_all(msg = 'Error')
begin
yield
rescue Exception => e
dputs(0) { "#{Time.now.strftime('%a %y.%m.%d-%H:%M:%S')} - #{msg}" }
dputs(0) { "#{e.inspect}" }
dputs(0) { "#{e.to_s}" }
e.backtrace.each { |l| dputs(0) { l } }
end
end
|
#run_bool(cmd) ⇒ Object
15
16
17
18
|
# File 'lib/helperclasses/system.rb', line 15
def run_bool(cmd)
dputs(3) { "Running command --#{cmd}--" }
Kernel.system("#{cmd} > /dev/null 2>&1")
end
|
#run_str(cmd) ⇒ Object
10
11
12
13
|
# File 'lib/helperclasses/system.rb', line 10
def run_str(cmd)
dputs(3) { "Running command --#{cmd}--" }
%x[ #{cmd} ]
end
|