Ruby verifies that something is mounted (- bind) in this directory

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)

How to check with ruby ​​(not shell !!) if any dir is installed on / mount _X?

Is there anything easier than opening / proc / mounts and finding / mount _X there?

+3
source share
4 answers

Another way to do this:

system("mount|grep /mount_X")
+1
source

As long as you are on Linux, you will find many answers directly when reading from the file system:

File.open('/proc/mounts').each do |line|
  device, mount_point, file_system_type, mount_options, dump, fsck_order  = line.split(" ")
end

which leads to the following solution for your problem:

if File.readlines('/proc/mounts').any?{ |line| line.split(" ")[1] == "/mount_X"}
    puts "Yes, it is mounted!!!"
end
+1
source

mount:

`mount`.split("\n").grep(/bind/).map { |x| x.split(" ")[2]  }
0

@tvw . /proc/  mountpoint mountpoint/folder_name.

 raise "Failed:  not mounted" 
 unless File.readlines('/proc/mounts').any?{ |line| line.split(" ")[1] =~ /folder_name$/ }
0

Source: https://habr.com/ru/post/1757314/


All Articles