{"id":127,"date":"2017-08-14T01:34:09","date_gmt":"2017-08-14T01:34:09","guid":{"rendered":"http:\/\/www.mrmarkyoung.com\/oracle\/?p=127"},"modified":"2018-06-04T16:50:30","modified_gmt":"2018-06-04T06:50:30","slug":"calculate-os-size-with-python","status":"publish","type":"post","link":"http:\/\/www.mrmarkyoung.com\/oracle\/2017\/08\/14\/calculate-os-size-with-python\/","title":{"rendered":"Calculate OS Size with Python"},"content":{"rendered":"\n<pre class=\"lang:default decode:true \" >df.py\r\n#! \/usr\/bin\/python\r\n# my first python attempt.\r\n# Mark Young 14 July 2016\r\nimport sys\r\nimport os\r\nimport subprocess\r\ndef reportUsage(label, total, free):\r\n  used = total - free\r\n  print \"%s=%dG, used=%dG (%d%%)\" % (label, free, used, used*100\/total)\r\np = subprocess.Popen([\"df\", \"-k\", \".\"], stdout=subprocess.PIPE)\r\nprint p.stdout.read()\r\nrc = p.wait()\r\nstat = os.statvfs(\".\")\r\ntotal = (stat.f_bsize * stat.f_blocks) \/ 1024 \/ 1024\/1024\r\nfree = (stat.f_bsize * stat.f_bfree) \/ 1024 \/ 1024\/1024\r\navail = (stat.f_bsize * stat.f_bavail) \/ 1024 \/ 1024\/1024\r\nprint \"Total=%dG\" % total\r\nreportUsage(\"Free\", total, free)\r\nreportUsage(\"Avail\", total, avail)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>df.py #! \/usr\/bin\/python # my first python attempt. # Mark Young 14 July 2016 import sys import os import subprocess def reportUsage(label, total, free): used = total &#8211; free print &#8220;%s=%dG, used=%dG (%d%%)&#8221; % (label, free, used, used*100\/total) p = subprocess.Popen([&#8220;df&#8221;, &#8220;-k&#8221;, &#8220;.&#8221;], stdout=subprocess.PIPE) print p.stdout.read() rc = p.wait() stat = os.statvfs(&#8220;.&#8221;) total = (stat.f_bsize &#8230; <a title=\"Calculate OS Size with Python\" class=\"read-more\" href=\"http:\/\/www.mrmarkyoung.com\/oracle\/2017\/08\/14\/calculate-os-size-with-python\/\" aria-label=\"Read more about Calculate OS Size with Python\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[31,65],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-unix"],"_links":{"self":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":1,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":128,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/127\/revisions\/128"}],"wp:attachment":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}