April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

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>