Spazio disco (reprise)

Salve
come faccio a conoscere lo spazio libero su un disco in ruby (e s.o.
linux)?
Mi spiego meglio
puts “il disco è quasi pieno” if spazio_libero_su_disco<1000
ho cercato in tutti i modi ma non trovo niente.

Simone [email protected] writes:

Salve
come faccio a conoscere lo spazio libero su un disco in ruby (e s.o.
linux)?

df_output = df -h.to_a.collect { |line| line.split }

disk = “/dev/disk0s2”

disk_info = df_output.find {|disk_info| disk_info[0] == disk }

spazio_libero_su_disco = disk_info[3]

Mi spiego meglio
puts “il disco è quasi pieno” if spazio_libero_su_disco<1000
ho cercato in tutti i modi ma non trovo niente.

Per curiosita’ quali sono “tutti” i modi?

Strace ti dice tutto:

statfs64("/", 84, {f_type=“EXT2_SUPER_MAGIC”, f_bsize=1024,
f_blocks=72041022, f_bfree=61104709, f_bavail=57444301,
f_files=9151488, f_ffree=8531825, f_fsid={1848060334, -1145266603},
f_namelen=255, f_frsize=1024}) = 0
statfs64("/sys", 84, {f_type=“SYSFS_MAGIC”, f_bsize=4096, f_blocks=0,
f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={0, 0},
f_namelen=255, f_frsize=4096}) = 0
statfs64("/var/run", 84, {f_type=0x1021994, f_bsize=4096,
f_blocks=258353, f_bfree=258318, f_bavail=258318, f_files=224143,
f_ffree=224073, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs64("/var/lock", 84, {f_type=0x1021994, f_bsize=4096,
f_blocks=258353, f_bfree=258353, f_bavail=258353, f_files=224143,
f_ffree=224141, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs64("/proc/bus/usb", 84, {f_type=0x1021994, f_bsize=4096,
f_blocks=258353, f_bfree=258322, f_bavail=258322, f_files=224143,
f_ffree=221184, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs64("/dev", 84, {f_type=0x1021994, f_bsize=4096, f_blocks=258353,
f_bfree=258322, f_bavail=258322, f_files=224143, f_ffree=221184,
f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs64("/dev/shm", 84, {f_type=0x1021994, f_bsize=4096,
f_blocks=258353, f_bfree=258353, f_bavail=258353, f_files=224143,
f_ffree=224142, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs64("/dev/pts", 84, {f_type=“DEVPTS_SUPER_MAGIC”, f_bsize=4096,
f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={0,
0}, f_namelen=255, f_frsize=4096}) = 0
statfs64("/boot", 84, {f_type=“EXT2_SUPER_MAGIC”, f_bsize=1024,
f_blocks=197599, f_bfree=160084, f_bavail=150044, f_files=25200,
f_ffree=25162, f_fsid={-544709901, 123230591}, f_namelen=255,
f_frsize=1024}) = 0
statfs64("/lib/modules/2.6.20-16-generic/volatile", 84,
{f_type=0x1021994, f_bsize=4096, f_blocks=258353, f_bfree=249906,
f_bavail=249906, f_files=224143, f_ffree=224126, f_fsid={0, 0},
f_namelen=255, f_frsize=4096}) = 0
statfs64("/proc/sys/fs/binfmt_misc", 84, {f_type=0x42494e4d,
f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0,
f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
write(1, “Filesystem Size Used Avail Use% Mounted
on\n/dev/sda6 69G 11G 55G 16% /\nvarrun
1010M 140K 1010M 1% /var/run\nvarlock 1010M 0
1010M 0% /var/lock\nprocbususb 1010M 124K 1010M 1%
/proc/bus
/usb\nudev 1010M 124K 1010M 1% /dev\ndevshm
1010M 0 1010M 0% /dev/shm\n/dev/sda3 193M
37M 147M 21% /boot\ntmpfs 1010M 33M 977M 4%
/lib/modules/2.6.20-16-generic/volatil”…, 502) = 502

Non so, poi, se esiste una libreria ruby per interfacciarti a quel
syscall - al limite scrivi una piccola estensione in C.

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