How to get disk free space using python

from subprocess import Popen, PIPE
import re

def disk_space(pattern="2[0-9]%", message="CAPACITY WARNING:"):

#takes shell command output
ps = Popen("df -h", shell=True,stdout=PIPE, stderr=PIPE)
output_lines = ps.stdout.readlines()
for line in output_lines:
line = line.strip()
if re.search(pattern,line):
print "%s %s" % (message,line)

disk_space()

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: