From 291e586aa3e0c514d2228b61fbc1afc1763aabb4 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 30 Oct 2020 16:52:52 -0400 Subject: [PATCH] Add net interface status to motd --- home/lib/login_functions.sh | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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 -- 2.20.1