Ruby module to get df -h output

Hi
i can get mount information by using
df -h

but wondering, if is there is any ruby module which will go through the
LInux mount information

basically i want to see

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p3 134G 12G 116G 9% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/cciss/c0d0p1 194M 28M 157M 15% /boot
/dev/cciss/c0d1p1 270G 1.5G 254G 1% /var/www/html

if /dev/cciss/c0d1p1 is mounted or not

as i SAid i can do this by df -h command

but i m trying to see if i can do this by using ruby modules

Thanks

You could easily write one in around 23 lines of code:

class MountPoints

Left as an exercise for the reader

end

mp = MountPoints.new

mp.is_mounted("/dev/disk2s2") => true
mp.is_mounted("/dev/disk3s2") => false

Well those values are correct for my system :slight_smile:

I doubt that there is a gem that does nothing but this given the
trivial nature of the problem.

There is however a simpler solution. The File class:

irb(main):001:0> File.exists?("/dev/disk2s2")
=> true
irb(main):002:0> File.exists?("/dev/disk3s2")
=> false

Peter H. wrote in post #1074238:

I doubt that there is a gem that does nothing but this given the
trivial nature of the problem.

http://sysutils.rubyforge.org/
->
https://github.com/djberg96/sys-filesystem

There is however a simpler solution. The File class:

irb(main):001:0> File.exists?("/dev/disk2s2")
=> true

But that doesn’t tell you if it is mounted or not.

Depends on your need

Here is the out put from ‘df -h’ on my system’

Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s2 465Gi 385Gi 80Gi 83% /
devfs 191Ki 191Ki 0Bi 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% /net
map auto_home 0Bi 0Bi 0Bi 100% /home
/dev/disk2s2 1.4Ti 489Gi 908Gi 36% /Volumes/Backup
/dev/disk1s6 466Gi 317Gi 148Gi 69% /Volumes/Spare

Now insert a new drive and do it again

Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s2 465Gi 385Gi 80Gi 83% /
devfs 195Ki 195Ki 0Bi 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% /net
map auto_home 0Bi 0Bi 0Bi 100% /home
/dev/disk2s2 1.4Ti 489Gi 908Gi 36% /Volumes/Backup
/dev/disk1s6 466Gi 317Gi 148Gi 69% /Volumes/Spare
/dev/disk3s1 56Mi 37Mi 19Mi 66% /Volumes/Untitled

Note the new filesystem => /dev/disk3s1

ruby-1.8.7-p302 > File.exists?("/dev/disk3s1")
=> true
ruby-1.8.7-p302 >

Now I remove the disk and we go back to how it was

Filesystem Size Used Avail Capacity Mounted on
/dev/disk0s2 465Gi 385Gi 80Gi 83% /
devfs 193Ki 193Ki 0Bi 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% /net
map auto_home 0Bi 0Bi 0Bi 100% /home
/dev/disk2s2 1.4Ti 489Gi 908Gi 36% /Volumes/Backup
/dev/disk1s6 466Gi 317Gi 148Gi 69% /Volumes/Spare

See that /dev/disk3s1 is no longer there

ruby-1.8.7-p302 > File.exists?("/dev/disk3s1")
=> false
ruby-1.8.7-p302 >

So as far as my system is concerned /dev/disk3s1 only exists when it
is mounted. This may be sufficient for the task that the OP had. Now I
will concede that it might not work how you might expect for other
devices. File.exists?("/dev/disk0s1") which is not in the df -h list
does return true as it is part of /dev/disk0s2. But the the OP didn’t
want to know if “/var/www/html” was mounted (or that the mount point
existed) just that “/dev/cciss/c0d1p1” was mounted, the example that
the OP gives would be true if “/dev/cciss/c0d1p1” was mounted to any
mount point not just “/var/www/html”.

As I’ve said File.exists?() might be a sufficient solution for the OP.

Peter H. wrote in post #1074298:

So as far as my system is concerned /dev/disk3s1 only exists when it
is mounted.

While the drive is inserted, type “umount /dev/disk3s1” and you will be
in a position where the disk exists but is not mounted. Ejecting via a
GUI filemanager is probably the same.

But the the OP didn’t
want to know if “/var/www/html” was mounted (or that the mount point
existed) just that “/dev/cciss/c0d1p1” was mounted, the example that
the OP gives would be true if “/dev/cciss/c0d1p1” was mounted to any
mount point not just “/var/www/html”.

Correct - which you can’t tell by looking at whether /dev/cciss/c0d1p1
exists.

But as you say, only the OP knows what solution they actually need.

Regards,

Brian.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs