module Adminix::Helpers::Command
Public Class Methods
darwin_cpu_load()
click to toggle source
# File lib/adminix/helpers/command.rb, line 50 def self.darwin_cpu_load `ps -A -o %cpu | awk '{s+=$1} END {print s}'`.to_f end
darwin_disk_usage()
click to toggle source
# File lib/adminix/helpers/command.rb, line 66 def self.darwin_disk_usage output = `df -h | awk '$NF=="/"{printf "%d/%d", $3,$2,$5}'` used, disk_size = output.split('/') [used.to_f * 1024, disk_size.to_f * 1024] end
darwin_memory_load()
click to toggle source
# File lib/adminix/helpers/command.rb, line 41 def self.darwin_memory_load output = `free -m | awk 'NR==2{printf "%s/%s", $3,$2,$3*100/$2 }'` output.split('/') end
debian_cpu_load()
click to toggle source
# File lib/adminix/helpers/command.rb, line 46 def self.debian_cpu_load `top -bn1 | grep load | awk '{printf "%.2f\\\n", $(NF-2)}'`.to_f end
debian_disk_usage()
click to toggle source
# File lib/adminix/helpers/command.rb, line 54 def self.debian_disk_usage output = `df -h | awk '$NF=="/"{printf "%d/%d\\\n", $3,$2,$5}'` output.split('/') end
debian_memory_load()
click to toggle source
# File lib/adminix/helpers/command.rb, line 32 def self.debian_memory_load output = `free -m | awk 'NR==2{printf "%s/%s", $3,$2,$3*100/$2 }'` output.split('/') end
debian_temperature()
click to toggle source
# File lib/adminix/helpers/command.rb, line 59 def self.debian_temperature output = `cat /sys/class/thermal/thermal_zone*/temp` temperatures = output.split("\n").map(&:to_i) return nil if temperatures.empty? temperatures.reduce(:+) / temperatures.size end
git_clone(repo, branch = 'master')
click to toggle source
# File lib/adminix/helpers/command.rb, line 19 def self.git_clone(repo, branch = 'master') bin = 'git' `#{bin} clone #{repo} -b #{branch}` end
home()
click to toggle source
# File lib/adminix/helpers/command.rb, line 15 def self.home ENV['HOME'] end
run_system_command(command)
click to toggle source
# File lib/adminix/helpers/command.rb, line 28 def self.run_system_command(command) `#{command}` end
systemctl_enabled?()
click to toggle source
# File lib/adminix/helpers/command.rb, line 37 def self.systemctl_enabled? !`which systemctl`.length.zero? end
which(arg1)
click to toggle source
# File lib/adminix/helpers/command.rb, line 4 def self.which(arg1) output = `which #{arg1}` output = output.split("\n")[0] output.empty? ? nil : output end
whoami()
click to toggle source
# File lib/adminix/helpers/command.rb, line 10 def self.whoami output = `whoami` output.split("\n")[0] end
Public Instance Methods
mkdir_p(dirname)
click to toggle source
# File lib/adminix/helpers/command.rb, line 24 def mkdir_p(dirname) `mkdir -p #{dirname}` end