I am attempting to gather basic disk space information from a server using a bash script, and store the output in JSON format. I am looking to record the available & use
You can do:
$ df -Ph | awk '/^\// {print $1"\t"$2"\t"$4}' | python -c 'import json, fileinput; print json.dumps({"diskarray":[dict(zip(("mount", "spacetotal", "spaceavail"), l.split())) for l in fileinput.input()]}, indent=2)'
{
"diskarray": [
{
"mount": "/dev/disk1",
"spacetotal": "931Gi",
"spaceavail": "623Gi"
},
{
"mount": "/dev/disk2s2",
"spacetotal": "1.8Ti",
"spaceavail": "360Gi"
}
]
}