{"id":6600,"date":"2017-04-03T17:15:30","date_gmt":"2017-04-03T09:15:30","guid":{"rendered":"http:\/\/rmohan.com\/?p=6600"},"modified":"2017-04-03T17:15:30","modified_gmt":"2017-04-03T09:15:30","slug":"python-code-for-disk-space","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6600","title":{"rendered":"python code for disk space"},"content":{"rendered":"<p>#!\/usr\/bin\/env python<br \/>\n#coding:utf-8<br \/>\nimport subprocess<br \/>\nimport json<br \/>\nimport os,sys<br \/>\nspace = []<br \/>\ndf= os.popen(&#8216;df -P -k&#8217;).read()<br \/>\ndf = subprocess.Popen([&#8220;df&#8221;, &#8220;-P&#8221;, &#8220;-k&#8221;], stdout=subprocess.PIPE)<br \/>\noutput = df.communicate()[0]<br \/>\nfor line in output.split(&#8220;\\n&#8221;)[1:]:<br \/>\nif len(line):<br \/>\ntry:<br \/>\ndevice, size, used, available, percent, mountpoint = line.split()<br \/>\nspace.append(dict(mountpoint=mountpoint, available=available))<br \/>\nexcept:<br \/>\npass<br \/>\nprint json.dumps(dict(space=space), indent=4)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/env python #coding:utf-8 import subprocess import json import os,sys space = [] df= os.popen(&#8216;df -P -k&#8217;).read() df = subprocess.Popen([&#8220;df&#8221;, &#8220;-P&#8221;, &#8220;-k&#8221;], stdout=subprocess.PIPE) output = df.communicate()[0] for line in output.split(&#8220;\\n&#8221;)[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)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6600"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6600"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6600\/revisions"}],"predecessor-version":[{"id":6601,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6600\/revisions\/6601"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}