Posts

Showing posts from September, 2014

JSON output from DF

So I'm adding more capabilities to my sysinfo.py program. The next thing that I want to do is get a JSON result from df . This is a function whose description, from the man page, says "report file system disk space usage". Here is a sample of the output of df for one of my systems: Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/flapjack-root 959088096 3802732 906566516 1% / udev 1011376 4 1011372 1% /dev tmpfs 204092 288 203804 1% /run none 5120 0 5120 0% /run/lock none 1020452 0 1020452 0% /run/shm /dev/sda1 233191 50734 170016 23% /boot So I started by writing a little Python program that used the subprocess.check_output() method to capture the output of df . This went through various iterations and ended up with this single line of python code, which requires eleven lines...