Store output diskspace df -h JSON

后端 未结 4 1328
不知归路
不知归路 2021-01-07 02:34

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

4条回答
  •  难免孤独
    2021-01-07 03:06

    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%"
          }
       ]
    }
    

提交回复
热议问题