1#!/usr/bin/env python 2 3"""This collects filesystem capacity info using the 'df' command. Tuples of 4filesystem name and percentage are stored in a list. A simple report is 5printed. Filesystems over 95% capacity are highlighted. Note that this does not 6parse filesystem names after the first space, so names with spaces in them will 7be truncated. This will produce ambiguous results for automount filesystems on 8Apple OSX. """ 9 10import pexpect 11 12child = pexpect.spawn ('df') 13 14# parse 'df' output into a list. 15pattern = "\n(\S+).*?([0-9]+)%" 16filesystem_list = [] 17for dummy in range (0, 1000): 18 i = child.expect ([pattern, pexpect.EOF]) 19 if i == 0: 20 filesystem_list.append (child.match.groups()) 21 else: 22 break 23 24# Print report 25print 26for m in filesystem_list: 27 s = "Filesystem %s is at %s%%" % (m[0], m[1]) 28 # highlight filesystems over 95% capacity 29 if int(m[1]) > 95: 30 s = '! ' + s 31 else: 32 s = ' ' + s 33 print s 34 35