I have a collection of Linux servers, each of which has a local hard drive with a /tmp directory. Occasionally, the /tmp directory on a server will fill up and cause errors. I want to automate the process of checking for free space on each local drive so that /tmp can be cleaned before it causes a problem. Is there an elegant, programmatic way to determine the amount of free space on a disk on Linux? I know the "classical" answer is to run
df -h
on each server (perhaps using a distributed shell tool such as dsh) and write a script to parse the output. Many such scripts can be found online. I am looking for a more elegant solution, such as a newer disk utility that returns structured data, or some information buried in the /proc filesystem.
The DU command uses statfs to collect data from the mounted filesystems. The mount filesystems seems to be determined by looking at the mtab file.
So if you want to connect the details you could quickly hack up a python (or whatever) script that calls statfs/statvfs and then give you the information in whatever format you like.