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