mount
/project on /mount_1 type none (rw,bind)
/project on /mount_2 type none (rw,bind)
/project on /mount_3 type none (rw,bind)
如何检查ruby(不是shell !!)是否在/ mount_X上安装了某个目录?
有什么比打开/ proc / mounts和在那里寻找/ mount_X更容易吗?
答案 0 :(得分:1)
另一种方法是:
system("mount|grep /mount_X")
答案 1 :(得分:1)
只要您使用Linux,就可以通过从文件系统中直接找到许多答案:
File.open('/proc/mounts').each do |line|
device, mount_point, file_system_type, mount_options, dump, fsck_order = line.split(" ")
end
为您的问题提供以下解决方案:
if File.readlines('/proc/mounts').any?{ |line| line.split(" ")[1] == "/mount_X"}
puts "Yes, it is mounted!!!"
end
答案 2 :(得分:0)
您只需解析mount
命令的输出:
`mount`.split("\n").grep(/bind/).map { |x| x.split(" ")[2] }
答案 3 :(得分:0)
@ tvw的回答有点扭曲了。逐行读取/ proc / mounts并在其上进行部分字符串匹配
mountpoint完整路径mountpoint/folder_name
。
raise "Failed: not mounted"
unless File.readlines('/proc/mounts').any?{ |line| line.split(" ")[1] =~ /folder_name$/ }