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
Xidel, together with some XQuery magic can do what you want (I used your df -h output).
df -h | xidel -s - --xquery '
{
"diskarray":[
for $x in x:lines($raw)[starts-with(.,"/")]
let $a:=tokenize($x,"\s+")
return {
"mount":$a[1],
"spacetotal":$a[2],
"spaceavail":$a[4]
}
]
}
'
{
"diskarray": [
{
"mount": "/dev/mapper/nodequery--vg-root",
"spacetotal": "45G",
"spaceavail": "41G"
},
{
"mount": "/dev/sda2",
"spacetotal": "237M",
"spaceavail": "178M"
},
{
"mount": "/dev/sda1",
"spacetotal": "511M",
"spaceavail": "508M"
}
]
}