Use jq for formatting ip addresses in netstatus.sh
This commit is contained in:
parent
75c18905b8
commit
cce8cf0917
@ -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>"
|
||||
|
Loading…
Reference in New Issue
Block a user