From: Siraaj Khandkar Date: Fri, 30 Oct 2020 20:52:52 +0000 (-0400) Subject: Add net interface status to motd X-Git-Url: https://git.xandkar.net/?p=khome.git;a=commitdiff_plain;h=291e586aa3e0c514d2228b61fbc1afc1763aabb4 Add net interface status to motd --- diff --git a/home/lib/login_functions.sh b/home/lib/login_functions.sh index 2a90695..29b00ee 100644 --- a/home/lib/login_functions.sh +++ b/home/lib/login_functions.sh @@ -437,6 +437,49 @@ motd() { ;; esac + echo + + (ifconfig; iwconfig) 2> /dev/null \ + | awk ' + /^[^ ]/ { + device = $1 + sub(":$", "", device) + if ($4 ~ "ESSID:") { + _essid = $4 + sub("^ESSID:\"", "", _essid) + sub("\"$", "", _essid) + essid[device] = _essid + } + next + } + + /^ / && $1 == "inet" { + address[device] = $2 + next + } + + /^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ { + split($2, lq_parts_eq, "=") + split(lq_parts_eq[2], lq_parts_slash, "/") + cur = lq_parts_slash[1] + max = lq_parts_slash[2] + link[device] = cur / max * 100 + next + } + + END { + for (device in address) + if (device != "lo") { + l = link[device] + e = essid[device] + l = l ? l : "--" + e = e ? e : "--" + print device, address[device], e, l + } + } + ' \ + | column -t + #echo # TODO: netstat summary # WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat