Remove loggers report from motd
[khome.git] / home / lib / login_functions.sh
index 293e7b4..9730feb 100644 (file)
@@ -376,6 +376,7 @@ bar_gauge() {
     awk "$@" '
         BEGIN {
             # CLI options
+            width    = width    ? width    : 80
             ch_left  = ch_left  ? ch_left  : "["
             ch_right = ch_right ? ch_right : "]"
             ch_blank = ch_blank ? ch_blank : "-"
@@ -410,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')
@@ -446,7 +465,6 @@ indent() {
 }
 
 motd() {
-    local -r bar_width='60'
     local -r indent_unit='    '
 
     uname -srvmo
@@ -467,7 +485,7 @@ motd() {
         df ~ | awk 'NR == 2 {print $3, $3 + $4, "disk"}'
         motd_batt
     ) \
-    | bar_gauge -v width="$bar_width" -v pct=1 \
+    | bar_gauge -v width=60 -v pct=1 \
     | column -t \
     | indent "$indent_unit"
 
@@ -549,28 +567,20 @@ motd() {
 
     echo
 
-    echo 'Loggers'
-    awk '
-        {
-            split($5, prog, "[")
-            sub(":$", "", prog[1]) # if there were no [], than : will is left behind
-            print prog[1]
-        }' /var/log/syslog \
+    echo 'Process owners (top 5)'
+    ps -eo user \
     | awk '
-        {
-            n = split($1, path, "/")  # prog may be in path form
-            prog = path[n]
+        NR > 1 {
+            count_by_user[$1]++
             total++
-            count[prog]++
         }
 
         END {
-            for (prog in count)
-                print count[prog], total, prog
-        }' \
-    | sort -n -k 1 -r \
-    | bar_gauge -v width=30 -v num=1 -v ch_left=' ' -v ch_right=' ' -v ch_blank=' ' \
-    | column -t \
+            for (user in count_by_user)
+                print count_by_user[user], total, user
+        }
+        ' \
+    | flat_top_5 \
     | indent "${indent_unit}"
 }
 
@@ -595,3 +605,26 @@ ssh_invalid_attempts_from() {
     | bar_gauge -v width="$(stty size | awk '{print $2}')" -v num=1 -v ch_right=' ' -v ch_left=' ' -v ch_blank=' ' \
     | column -t
 }
+
+loggers() {
+    awk '
+        {
+            split($5, prog, "[")
+            sub(":$", "", prog[1]) # if there were no [], than : will is left behind
+            print prog[1]
+        }' /var/log/syslog \
+    | awk '
+        {
+            n = split($1, path, "/")  # prog may be in path form
+            prog = path[n]
+            total++
+            count[prog]++
+        }
+
+        END {
+            for (prog in count)
+                print count[prog], total, prog
+        }' \
+    | bar_gauge -v num=1 -v ch_right=' ' -v ch_left=' ' -v ch_blank=' ' \
+    | column -t
+}
This page took 0.042304 seconds and 4 git commands to generate.