Use jq for formatting ip addresses in netstatus.sh

This commit is contained in:
Adam Goldsmith 2022-10-02 18:56:08 -04:00
parent 75c18905b8
commit cce8cf0917
1 changed files with 8 additions and 11 deletions

View File

@ -8,15 +8,12 @@ function doPing () {
sed 's/.*time=\([0-9\.]*\).*/'"$2"':\1ms/'
}
if [[ "$@" -ne "" ]]
then
interfaces=$(ip -4 -o a | grep "$@")
else
interfaces=$(ip -4 -o a)
fi
ip=$(echo "$interfaces" | \
sed 's/^[0-9]*: \([^ ]*\) inet \([0-9.]*\).*/\1:\2/g' | \
grep -v lo | \
tr '\n' ' ')
function get_ip_addresses() {
ip -4 -json address | jq -r '
map(select(.ifname != "lo") |
.ifname + ":" + (.addr_info | map(.local) | join(","))) |
join(" ")
'
}
echo -n "<txt>${ip}$(doPing 8.8.8.8 G)</txt>"
echo -n "<txt>$(get_ip_addresses) $(doPing 8.8.8.8 G)</txt>"