检测NFS设置是否合法

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

  def check_mount_nfs_1(ip,path)
    rtn = `/bin/ping -q -c 1 #{ip}`
    if $?.exitstatus == 0
      rtn = `/sbin/showmount -e #{ip}`
      if $?.exitstatus == 0
        lines = rtn.split(/\n/)
        for line in lines do
          if line.start_with?(path)
            return true
          end
        end
      end
    end
    return false
  end 

  def check_mount_nfs_2(ip,path)
    require 'ping'
    result = Ping.pingecho(ip, 10)
    if result
      rtn = `/sbin/showmount -e #{ip}`
      if $?.exitstatus == 0
        lines = rtn.split(/\n/)
        for line in lines do
          if line.start_with?(path)
            return true
          end
        end
      end
    end
    return false
  end