From 9699e21d467d3f7d8577aa283dc73c9d7bcef9f9 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 2 Nov 2020 09:10:53 -0500 Subject: [PATCH] Compact loggers and proc owners report --- home/lib/login_functions.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/home/lib/login_functions.sh b/home/lib/login_functions.sh index 8057711..e17c5c6 100644 --- a/home/lib/login_functions.sh +++ b/home/lib/login_functions.sh @@ -411,6 +411,24 @@ bar_gauge() { ' } +flat_top_5() { + sort -n -k 1 -r \ + | head -5 \ + | awk ' + { + cur = $1 + max = $2 + name = $3 + pct = cur / max * 100 + printf "%s%s:%.2f%%", sep, name, pct + sep = " " + } + + END {printf "\n"} + ' \ + | column -t +} + motd_batt() { case "$(uname)" in 'Linux') @@ -549,7 +567,7 @@ motd() { echo - echo 'Process owners' + echo 'Process owners (top 5)' ps -eo user \ | awk ' NR > 1 { @@ -562,9 +580,7 @@ motd() { print count_by_user[user], total, user } ' \ - | sort -n -k 1 -r \ - | bar_gauge -v num=1 -v ch_left=' ' -v ch_right=' ' -v ch_blank=' ' \ - | column -t \ + | flat_top_5 \ | indent "${indent_unit}" echo @@ -588,10 +604,7 @@ motd() { for (prog in count) print count[prog], total, prog }' \ - | sort -n -k 1 -r \ - | head -5 \ - | bar_gauge -v width=30 -v num=1 -v ch_left=' ' -v ch_right=' ' -v ch_blank=' ' \ - | column -t \ + | flat_top_5 \ | indent "${indent_unit}" } -- 2.20.1