From 94df2def5a3ab95bca8cdef99301d1cc39b8cab1 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Sun, 22 Dec 2019 11:19:43 -0500 Subject: [PATCH] Implement shell_activity_report function --- home/lib/login_functions.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/home/lib/login_functions.sh b/home/lib/login_functions.sh index e006eee..87746c6 100644 --- a/home/lib/login_functions.sh +++ b/home/lib/login_functions.sh @@ -5,6 +5,31 @@ d() { dict "$word" } +shell_activity_report() { + history \ + | awk ' + { + time = $3 + ok = split(time, t, ":") + if (ok) { + hour = t[1] + 0 # Coerce number from string + cnt = count[hour]++ + } + if (cnt > max) + max = cnt + } + + END { + for (hour=0; hour<24; hour++) { + c = count[hour] + printf "%2d ", hour + for (i=1; i<=((c * 100) / max); i++) + printf "|" + printf "\n" + } + }' +} + top_commands() { history \ | awk ' -- 2.20.1