V
V
Vadim2021-05-06 14:25:25
linux
Vadim, 2021-05-06 14:25:25

Is it possible to display the size of all disks in json format using one command?

Hello everyone,

I'm displaying the size of the disks attached to the instance:

[email protected]:# df -hT | grep -v overlay | grep -v shm | grep \/dev | grep -v devtmpfs
/dev/nvme0n1p2 ext4      120G   55G   61G  48% /
/dev/nvme4n1   ext4       99G  291M   94G   1% /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/vol-0b3037141a35cb423
/dev/nvme3n1   ext4      493G  426G   46G  91% /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/vol-0aca325ffd5059834
/dev/nvme1n1   ext4       20G  693M   18G   4% /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/vol-060825f3bf5c1f862
/dev/nvme2n1   ext4      246G  189G   47G  81% /var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/vol-0d94c8142d28f9753


what command do you recommend... if there is one)) to change the output format to
{{"/dev/nvme0n1p2":"48%"}, {"/dev/nvme4n1": "1% "}.... }

all the best,
Vadim

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Romses Panagiotis, 2021-05-06
@Viji

Googled it:
https://stackoverflow.com/questions/35211716/store...
Also, excerpt from man df:

--output[=FIELD_LIST]
              use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted.

И далее внизу:

       FIELD_LIST is a comma-separated list of columns to be included.  Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size',
       'used', 'avail', 'pcent', 'file' and 'target' (see info page).

D
Dmitry, 2021-05-06
@dtmse

df -h --output="source,pcent" | tr -s ' ' | csvjson -d' '

csvjson - a utility from the csvkit package in Debian/Ubuntu

S
Saboteur, 2021-05-06
@saboteur_kiev

lsblk -J -o "FSUSE%,MOUNTPOINT"|tr -d '\n '

C
ComodoHacker, 2021-05-06
@ComodoHacker

An awk/perl/sed script will do the trick.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question