5th
Parsing Free space Output
Here’s a really short regex that can be used to parse free space output and verify each mounted disk has at least 89% free space. This comes in handy if you do any of your own systems monitoring that include *nix boxes.
So let’s say you have this output from various machines:
db:
Filesystem Size Used Avail Use% Mounted on
47G 3.1G 41G 7% /
/dev/sda1 99M 16M 79M 17% /boot
tmpfs 1.5G 0 1.5G 0% /dev/shm
www:
Filesystem Size Used Avail Use% Mounted on
76G 16G 56G 22% /
/dev/sda1 99M 17M 78M 18% /boot
tmpfs 1.5G 0 1.5G 0% /dev/shm
email:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 13G 4.1G 9.0G 32% /
udev 1.9G 116K 1.9G 1% /dev
/dev/sdb1 241G 15G 214G 7% /var/data
/dev/sdc1 241G 15G 214G 7% /var/backup
This regex will do the trick:
/([9]).%/
It can be integrated into a Ruby statement as follows:
IO.popen(“cat /path/to/freespace_output 2>&1”) do |f|
while line = f.gets do
lowdisk_systems += 1 if line =~ /([9]).%/i
end
end
In this case, lowdisk_systems gets incremented for each line of “/path/to/freespace_output” that is 90% or greater.
This example by itself is extremely limited in scope, but if integrated properly it can be useful.
