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
Alternative Oneliner
$ df -hP | awk 'BEGIN {printf"{\"discarray\":["}{if($1=="Filesystem")next;if(a)printf",";printf"{\"mount\":\""$6"\",\"size\":\""$2"\",\"used\":\""$3"\",\"avail\":\""$4"\",\"use%\":\""$5"\"}";a++;}END{print"]}";}'
{
"discarray":[
{
"mount":"/",
"size":"3.9G",
"used":"2.2G",
"avail":"1.5G",
"use%":"56%"
},
{
"mount":"/dev",
"size":"24G",
"used":"0",
"avail":"24G",
"use%":"0%"
}
]
}