Store output diskspace df -h JSON












0















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 & used disk space.



An example output of df -h:



Filesystem                      Size  Used Avail Use% Mounted on
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 394M 288K 394M 1% /run
/dev/mapper/nodequery--vg-root 45G 1.4G 41G 4% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 0 2.0G 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda2 237M 47M 178M 21% /boot
/dev/sda1 511M 3.4M 508M 1% /boot/efi


As an example this is how I would like the final output to look.



{
"diskarray": [{
"mount": "/dev/disk1",
"spacetotal": "35GB",
"spaceavail": "1GB"
},
{
"mount": "/dev/disk2",
"spacetotal": "35GB",
"spaceavail": "4GB"
}]
}


So far I've tried using awk:



df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'


with the following output:



/dev/mapper/nodequery--vg-root 47710605312 1439592448;
/dev/sda2 247772160 48645120;
/dev/sda1 535805952 3538944;


But I'm not sure how I take that data and store it in the JSON format.










share|improve this question

























  • I've got to this: df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'

    – westcoastdev
    Feb 4 '16 at 21:14






  • 1





    You should edit your question to include your attempted solution, and tell us what problems you're having with it. You will get better reaction to "here's what I tried, and here's how it doesn't work" rather than "I want to do this, tell me how."

    – miken32
    Feb 4 '16 at 21:17













  • Sorry i edited, fairly new to this site & bash in general, going off other examples I've found doing similar things.

    – westcoastdev
    Feb 4 '16 at 21:19













  • Have you looked at jq (a tool built for this kind of use case)?

    – Charles Duffy
    Feb 4 '16 at 21:21













  • @CharlesDuffy , I will take a look at that although I am trying to avoid having package requirements for the script to run

    – westcoastdev
    Feb 4 '16 at 21:28
















0















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 & used disk space.



An example output of df -h:



Filesystem                      Size  Used Avail Use% Mounted on
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 394M 288K 394M 1% /run
/dev/mapper/nodequery--vg-root 45G 1.4G 41G 4% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 0 2.0G 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda2 237M 47M 178M 21% /boot
/dev/sda1 511M 3.4M 508M 1% /boot/efi


As an example this is how I would like the final output to look.



{
"diskarray": [{
"mount": "/dev/disk1",
"spacetotal": "35GB",
"spaceavail": "1GB"
},
{
"mount": "/dev/disk2",
"spacetotal": "35GB",
"spaceavail": "4GB"
}]
}


So far I've tried using awk:



df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'


with the following output:



/dev/mapper/nodequery--vg-root 47710605312 1439592448;
/dev/sda2 247772160 48645120;
/dev/sda1 535805952 3538944;


But I'm not sure how I take that data and store it in the JSON format.










share|improve this question

























  • I've got to this: df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'

    – westcoastdev
    Feb 4 '16 at 21:14






  • 1





    You should edit your question to include your attempted solution, and tell us what problems you're having with it. You will get better reaction to "here's what I tried, and here's how it doesn't work" rather than "I want to do this, tell me how."

    – miken32
    Feb 4 '16 at 21:17













  • Sorry i edited, fairly new to this site & bash in general, going off other examples I've found doing similar things.

    – westcoastdev
    Feb 4 '16 at 21:19













  • Have you looked at jq (a tool built for this kind of use case)?

    – Charles Duffy
    Feb 4 '16 at 21:21













  • @CharlesDuffy , I will take a look at that although I am trying to avoid having package requirements for the script to run

    – westcoastdev
    Feb 4 '16 at 21:28














0












0








0


2






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 & used disk space.



An example output of df -h:



Filesystem                      Size  Used Avail Use% Mounted on
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 394M 288K 394M 1% /run
/dev/mapper/nodequery--vg-root 45G 1.4G 41G 4% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 0 2.0G 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda2 237M 47M 178M 21% /boot
/dev/sda1 511M 3.4M 508M 1% /boot/efi


As an example this is how I would like the final output to look.



{
"diskarray": [{
"mount": "/dev/disk1",
"spacetotal": "35GB",
"spaceavail": "1GB"
},
{
"mount": "/dev/disk2",
"spacetotal": "35GB",
"spaceavail": "4GB"
}]
}


So far I've tried using awk:



df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'


with the following output:



/dev/mapper/nodequery--vg-root 47710605312 1439592448;
/dev/sda2 247772160 48645120;
/dev/sda1 535805952 3538944;


But I'm not sure how I take that data and store it in the JSON format.










share|improve this question
















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 & used disk space.



An example output of df -h:



Filesystem                      Size  Used Avail Use% Mounted on
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 394M 288K 394M 1% /run
/dev/mapper/nodequery--vg-root 45G 1.4G 41G 4% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 0 2.0G 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda2 237M 47M 178M 21% /boot
/dev/sda1 511M 3.4M 508M 1% /boot/efi


As an example this is how I would like the final output to look.



{
"diskarray": [{
"mount": "/dev/disk1",
"spacetotal": "35GB",
"spaceavail": "1GB"
},
{
"mount": "/dev/disk2",
"spacetotal": "35GB",
"spaceavail": "4GB"
}]
}


So far I've tried using awk:



df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'


with the following output:



/dev/mapper/nodequery--vg-root 47710605312 1439592448;
/dev/sda2 247772160 48645120;
/dev/sda1 535805952 3538944;


But I'm not sure how I take that data and store it in the JSON format.







json bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 4 '16 at 21:19







westcoastdev

















asked Feb 4 '16 at 21:12









westcoastdevwestcoastdev

234




234













  • I've got to this: df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'

    – westcoastdev
    Feb 4 '16 at 21:14






  • 1





    You should edit your question to include your attempted solution, and tell us what problems you're having with it. You will get better reaction to "here's what I tried, and here's how it doesn't work" rather than "I want to do this, tell me how."

    – miken32
    Feb 4 '16 at 21:17













  • Sorry i edited, fairly new to this site & bash in general, going off other examples I've found doing similar things.

    – westcoastdev
    Feb 4 '16 at 21:19













  • Have you looked at jq (a tool built for this kind of use case)?

    – Charles Duffy
    Feb 4 '16 at 21:21













  • @CharlesDuffy , I will take a look at that although I am trying to avoid having package requirements for the script to run

    – westcoastdev
    Feb 4 '16 at 21:28



















  • I've got to this: df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'

    – westcoastdev
    Feb 4 '16 at 21:14






  • 1





    You should edit your question to include your attempted solution, and tell us what problems you're having with it. You will get better reaction to "here's what I tried, and here's how it doesn't work" rather than "I want to do this, tell me how."

    – miken32
    Feb 4 '16 at 21:17













  • Sorry i edited, fairly new to this site & bash in general, going off other examples I've found doing similar things.

    – westcoastdev
    Feb 4 '16 at 21:19













  • Have you looked at jq (a tool built for this kind of use case)?

    – Charles Duffy
    Feb 4 '16 at 21:21













  • @CharlesDuffy , I will take a look at that although I am trying to avoid having package requirements for the script to run

    – westcoastdev
    Feb 4 '16 at 21:28

















I've got to this: df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'

– westcoastdev
Feb 4 '16 at 21:14





I've got to this: df -P -B 1 | grep '^/' | awk '{ print $1" "$2" "$3";" }'

– westcoastdev
Feb 4 '16 at 21:14




1




1





You should edit your question to include your attempted solution, and tell us what problems you're having with it. You will get better reaction to "here's what I tried, and here's how it doesn't work" rather than "I want to do this, tell me how."

– miken32
Feb 4 '16 at 21:17







You should edit your question to include your attempted solution, and tell us what problems you're having with it. You will get better reaction to "here's what I tried, and here's how it doesn't work" rather than "I want to do this, tell me how."

– miken32
Feb 4 '16 at 21:17















Sorry i edited, fairly new to this site & bash in general, going off other examples I've found doing similar things.

– westcoastdev
Feb 4 '16 at 21:19







Sorry i edited, fairly new to this site & bash in general, going off other examples I've found doing similar things.

– westcoastdev
Feb 4 '16 at 21:19















Have you looked at jq (a tool built for this kind of use case)?

– Charles Duffy
Feb 4 '16 at 21:21







Have you looked at jq (a tool built for this kind of use case)?

– Charles Duffy
Feb 4 '16 at 21:21















@CharlesDuffy , I will take a look at that although I am trying to avoid having package requirements for the script to run

– westcoastdev
Feb 4 '16 at 21:28





@CharlesDuffy , I will take a look at that although I am trying to avoid having package requirements for the script to run

– westcoastdev
Feb 4 '16 at 21:28












3 Answers
3






active

oldest

votes


















1














The following does what you want, with the only requirement external to bash being a Python interpreter:



python_script=$(cat <<'EOF'
import sys, json

data = {'diskarray': }
for line in sys.stdin.readlines():
mount, avail, total = line.rstrip(';').split()
data['diskarray'].append(dict(mount=mount, spacetotal=total, spaceavail=avail))
sys.stdout.write(json.dumps(data))
EOF
)

df -Ph | awk '/^// { print $1" "$2" "$3";" }' | python -c "$python_script"


An alternate implementation using jq might look like this:



df -Ph | 
jq -R -s '
[
split("n") |
. |
if test("^/") then
gsub(" +"; " ") | split(" ") | {mount: .[0], spacetotal: .[1], spaceavail: .[2]}
else
empty
end
]'





share|improve this answer


























  • This is exactly what I was looking to do. Thank you so much!

    – westcoastdev
    Feb 4 '16 at 21:52











  • Glad to help! I've also added a jq implementation (that also does the work of awk internally).

    – Charles Duffy
    Feb 4 '16 at 23:27





















1














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





share|improve this answer

































    0














    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%":""$4""}";a++;}END{print"]}";}'

    {
    "discarray":[
    {
    "mount":"/",
    "size":"3.9G",
    "used":"2.2G",
    "avail":"1.5G",
    "use%":"1.5G"
    },
    {
    "mount":"/dev",
    "size":"24G",
    "used":"0",
    "avail":"24G",
    "use%":"24G"
    }
    ]
    }





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35211716%2fstore-output-diskspace-df-h-json%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The following does what you want, with the only requirement external to bash being a Python interpreter:



      python_script=$(cat <<'EOF'
      import sys, json

      data = {'diskarray': }
      for line in sys.stdin.readlines():
      mount, avail, total = line.rstrip(';').split()
      data['diskarray'].append(dict(mount=mount, spacetotal=total, spaceavail=avail))
      sys.stdout.write(json.dumps(data))
      EOF
      )

      df -Ph | awk '/^// { print $1" "$2" "$3";" }' | python -c "$python_script"


      An alternate implementation using jq might look like this:



      df -Ph | 
      jq -R -s '
      [
      split("n") |
      . |
      if test("^/") then
      gsub(" +"; " ") | split(" ") | {mount: .[0], spacetotal: .[1], spaceavail: .[2]}
      else
      empty
      end
      ]'





      share|improve this answer


























      • This is exactly what I was looking to do. Thank you so much!

        – westcoastdev
        Feb 4 '16 at 21:52











      • Glad to help! I've also added a jq implementation (that also does the work of awk internally).

        – Charles Duffy
        Feb 4 '16 at 23:27


















      1














      The following does what you want, with the only requirement external to bash being a Python interpreter:



      python_script=$(cat <<'EOF'
      import sys, json

      data = {'diskarray': }
      for line in sys.stdin.readlines():
      mount, avail, total = line.rstrip(';').split()
      data['diskarray'].append(dict(mount=mount, spacetotal=total, spaceavail=avail))
      sys.stdout.write(json.dumps(data))
      EOF
      )

      df -Ph | awk '/^// { print $1" "$2" "$3";" }' | python -c "$python_script"


      An alternate implementation using jq might look like this:



      df -Ph | 
      jq -R -s '
      [
      split("n") |
      . |
      if test("^/") then
      gsub(" +"; " ") | split(" ") | {mount: .[0], spacetotal: .[1], spaceavail: .[2]}
      else
      empty
      end
      ]'





      share|improve this answer


























      • This is exactly what I was looking to do. Thank you so much!

        – westcoastdev
        Feb 4 '16 at 21:52











      • Glad to help! I've also added a jq implementation (that also does the work of awk internally).

        – Charles Duffy
        Feb 4 '16 at 23:27
















      1












      1








      1







      The following does what you want, with the only requirement external to bash being a Python interpreter:



      python_script=$(cat <<'EOF'
      import sys, json

      data = {'diskarray': }
      for line in sys.stdin.readlines():
      mount, avail, total = line.rstrip(';').split()
      data['diskarray'].append(dict(mount=mount, spacetotal=total, spaceavail=avail))
      sys.stdout.write(json.dumps(data))
      EOF
      )

      df -Ph | awk '/^// { print $1" "$2" "$3";" }' | python -c "$python_script"


      An alternate implementation using jq might look like this:



      df -Ph | 
      jq -R -s '
      [
      split("n") |
      . |
      if test("^/") then
      gsub(" +"; " ") | split(" ") | {mount: .[0], spacetotal: .[1], spaceavail: .[2]}
      else
      empty
      end
      ]'





      share|improve this answer















      The following does what you want, with the only requirement external to bash being a Python interpreter:



      python_script=$(cat <<'EOF'
      import sys, json

      data = {'diskarray': }
      for line in sys.stdin.readlines():
      mount, avail, total = line.rstrip(';').split()
      data['diskarray'].append(dict(mount=mount, spacetotal=total, spaceavail=avail))
      sys.stdout.write(json.dumps(data))
      EOF
      )

      df -Ph | awk '/^// { print $1" "$2" "$3";" }' | python -c "$python_script"


      An alternate implementation using jq might look like this:



      df -Ph | 
      jq -R -s '
      [
      split("n") |
      . |
      if test("^/") then
      gsub(" +"; " ") | split(" ") | {mount: .[0], spacetotal: .[1], spaceavail: .[2]}
      else
      empty
      end
      ]'






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Feb 4 '16 at 23:25

























      answered Feb 4 '16 at 21:40









      Charles DuffyCharles Duffy

      178k25200256




      178k25200256













      • This is exactly what I was looking to do. Thank you so much!

        – westcoastdev
        Feb 4 '16 at 21:52











      • Glad to help! I've also added a jq implementation (that also does the work of awk internally).

        – Charles Duffy
        Feb 4 '16 at 23:27





















      • This is exactly what I was looking to do. Thank you so much!

        – westcoastdev
        Feb 4 '16 at 21:52











      • Glad to help! I've also added a jq implementation (that also does the work of awk internally).

        – Charles Duffy
        Feb 4 '16 at 23:27



















      This is exactly what I was looking to do. Thank you so much!

      – westcoastdev
      Feb 4 '16 at 21:52





      This is exactly what I was looking to do. Thank you so much!

      – westcoastdev
      Feb 4 '16 at 21:52













      Glad to help! I've also added a jq implementation (that also does the work of awk internally).

      – Charles Duffy
      Feb 4 '16 at 23:27







      Glad to help! I've also added a jq implementation (that also does the work of awk internally).

      – Charles Duffy
      Feb 4 '16 at 23:27















      1














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





      share|improve this answer






























        1














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





        share|improve this answer




























          1












          1








          1







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





          share|improve this answer















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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 4 '16 at 22:12

























          answered Feb 4 '16 at 21:57









          dawgdawg

          59.4k1283153




          59.4k1283153























              0














              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%":""$4""}";a++;}END{print"]}";}'

              {
              "discarray":[
              {
              "mount":"/",
              "size":"3.9G",
              "used":"2.2G",
              "avail":"1.5G",
              "use%":"1.5G"
              },
              {
              "mount":"/dev",
              "size":"24G",
              "used":"0",
              "avail":"24G",
              "use%":"24G"
              }
              ]
              }





              share|improve this answer




























                0














                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%":""$4""}";a++;}END{print"]}";}'

                {
                "discarray":[
                {
                "mount":"/",
                "size":"3.9G",
                "used":"2.2G",
                "avail":"1.5G",
                "use%":"1.5G"
                },
                {
                "mount":"/dev",
                "size":"24G",
                "used":"0",
                "avail":"24G",
                "use%":"24G"
                }
                ]
                }





                share|improve this answer


























                  0












                  0








                  0







                  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%":""$4""}";a++;}END{print"]}";}'

                  {
                  "discarray":[
                  {
                  "mount":"/",
                  "size":"3.9G",
                  "used":"2.2G",
                  "avail":"1.5G",
                  "use%":"1.5G"
                  },
                  {
                  "mount":"/dev",
                  "size":"24G",
                  "used":"0",
                  "avail":"24G",
                  "use%":"24G"
                  }
                  ]
                  }





                  share|improve this answer













                  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%":""$4""}";a++;}END{print"]}";}'

                  {
                  "discarray":[
                  {
                  "mount":"/",
                  "size":"3.9G",
                  "used":"2.2G",
                  "avail":"1.5G",
                  "use%":"1.5G"
                  },
                  {
                  "mount":"/dev",
                  "size":"24G",
                  "used":"0",
                  "avail":"24G",
                  "use%":"24G"
                  }
                  ]
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 13:33









                  MagnusMagnus

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35211716%2fstore-output-diskspace-df-h-json%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      Origin of the phrase “under your belt”?