November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

python code for disk space

#!/usr/bin/env python
#coding:utf-8
import subprocess
import json
import os,sys
space = []
df= os.popen(‘df -P -k’).read()
df = subprocess.Popen([“df”, “-P”, “-k”], stdout=subprocess.PIPE)
output = df.communicate()[0]
for line in output.split(“\n”)[1:]:
if len(line):
try:
device, size, used, available, percent, mountpoint = line.split()
space.append(dict(mountpoint=mountpoint, available=available))
except:
pass
print json.dumps(dict(space=space), indent=4)

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>