module HelperClasses::System
Public Instance Methods
exists?(cmd)
click to toggle source
# 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)
click to toggle source
# 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') { || ... }
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/helperclasses/system.rb, line 10 def run_str(cmd) dputs(3) { "Running command --#{cmd}--" } %x[ #{cmd} ] end