xfce4-panel/.config/xfce4/panel/scripts/netstatus.sh

20 lines
444 B
Bash
Executable File

#!/bin/bash
function doPing () {
# $1 = target
# $2 = letter
ping -c1 -W1 "$1" | \
(grep "bytes from" || echo "<span fgcolor=\"red\">$2:Down</span>") | \
sed 's/.*time=\([0-9\.]*\).*/'"$2"':\1ms/'
}
function get_ip_addresses() {
ip -4 -json address | jq -r '
map(select(.ifname != "lo") |
.ifname + ":" + (.addr_info | map(.local) | join(","))) |
join(" ")
'
}
echo -n "<txt>$(get_ip_addresses) $(doPing 8.8.8.8 G)</txt>"