2011-03-12 04:13:06 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""This collects filesystem capacity info using the 'df' command. Tuples of
|
|
|
|
filesystem name and percentage are stored in a list. A simple report is
|
|
|
|
printed. Filesystems over 95% capacity are highlighted. Note that this does not
|
|
|
|
parse filesystem names after the first space, so names with spaces in them will
|
|
|
|
be truncated. This will produce ambiguous results for automount filesystems on
|
|
|
|
Apple OSX. """
|
|
|
|
|
|
|
|
import pexpect
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
child = pexpect.spawn('df')
|
2011-03-12 04:13:06 +08:00
|
|
|
|
|
|
|
# parse 'df' output into a list.
|
|
|
|
pattern = "\n(\S+).*?([0-9]+)%"
|
|
|
|
filesystem_list = []
|
2016-09-07 04:57:50 +08:00
|
|
|
for dummy in range(0, 1000):
|
|
|
|
i = child.expect([pattern, pexpect.EOF])
|
2011-03-12 04:13:06 +08:00
|
|
|
if i == 0:
|
2016-09-07 04:57:50 +08:00
|
|
|
filesystem_list.append(child.match.groups())
|
2011-03-12 04:13:06 +08:00
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
# Print report
|
|
|
|
print
|
|
|
|
for m in filesystem_list:
|
|
|
|
s = "Filesystem %s is at %s%%" % (m[0], m[1])
|
|
|
|
# highlight filesystems over 95% capacity
|
|
|
|
if int(m[1]) > 95:
|
|
|
|
s = '! ' + s
|
|
|
|
else:
|
|
|
|
s = ' ' + s
|
|
|
|
print s
|