Skip to content

Instantly share code, notes, and snippets.

@Neos21

Neos21/df-json.sh

Created Sep 7, 2020
Embed
What would you like to do?
df JSON
#!/bin/sh
\df -P \
| tail -n +2 \
| awk '
BEGIN {
printf "{\n";
printf " \"volumes\": [\n";
}
{
if(a) printf ",\n";
printf " {\n";
printf " \"filesystem\": \""$1"\",\n";
printf " \"size\" : \""$2"\",\n";
printf " \"used\" : \""$3"\",\n";
printf " \"available\" : \""$4"\",\n";
printf " \"capacity\" : \""$5"\",\n";
printf " \"mounted_on\": \""$6"\"\n";
printf " }";
a++;
}
END {
printf "\n";
printf " ]\n";
printf "}";
}
' \
| jq '.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.