1. 程式人生 > >ruby連接liunx後臺返回/dev/sda分區大小

ruby連接liunx後臺返回/dev/sda分區大小

return command sta 名稱 host 返回 安裝 分區 star

#安裝gems包:net-ssh
#方法名稱:get_disk_size
#作用:獲取/dev/sda分區的大小
#作者: xiaowei


require ‘net/ssh‘

def get_disk_size(params={})
hostip = params[:hostip] #
hostuser = params[:hostuser]
hostpasswd = params[:hostpasswd]
command = params[:command]
ssh = Net::SSH.start(hostip,hostuser,:password=>hostpasswd)
ret = ssh.exec!(command)
ret =~ /disk\s+\/dev\/sda:\s+(\d+\.\d)\s+GB/i
return $1.to_f
end

p get_disk_size(
:hostip => "192.168.255.129",
:hostuser => "root",
:hostpasswd => "redhat",
:command => "fdisk -l"
)


ruby連接liunx後臺返回/dev/sda分區大小