#安装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"
)
时间: 2024-10-15 09:51:04