3bf767623cca07401ef73010fc7b01ae1b85b59e
[khome.git] / home / lib / login_functions.sh
1 #
2
3 ## notify_done : unit -> unit
4 notify_done() {
5 local -r _status_code="$?"
6 local -r _program="$1"
7 local _timestamp
8 _timestamp="$(timestamp)"
9 local -r _msg="$_timestamp [$_program] done "
10 if [[ "$_status_code" -eq 0 ]]
11 then
12 notify-send -u normal "$_msg OK: $_status_code"
13 else
14 notify-send -u critical "$_msg ERROR: $_status_code"
15 fi
16 }
17
18 ## p : string -> unit
19 p() {
20 awk \
21 -v _s="$1" \
22 '
23 BEGIN {_s = tolower(_s)}
24
25 # TODO fzf/dmenu select instead of searching:
26 /^[a-zA-Z]/ && tolower($1) ~ _s && NF >= 2 {
27 n++
28 s = $1
29 p = $NF
30 if (NF == 2) {
31 e = ""
32 u = ""
33 } else if (NF == 3) {
34 e = $2
35 u = ""
36 } else {
37 e = $2
38 u = $3
39 } # TODO What would NF > 4 mean?
40
41 printf("%d [O] s:\"%s\", e:\"%s\", u:\"%s\"\n", n, s, e, u) > "/dev/stderr"
42 if (match(u, "@")) {
43 tmp = e
44 e = u
45 u = tmp
46 printf("%d [C] s:\"%s\", e:\"%s\", u:\"%s\"\n", n, s, e, u) > "/dev/stderr"
47 }
48
49 printf "%s", p # XXX Intentionally avoiding newline in the result.
50 }
51
52 END {
53 if (n == 1) {
54 exit 0
55 } else if (n == 0) {
56 printf "[ERROR] Found nothing.\n" > "/dev/stderr"
57 exit 1
58 } else if (n > 1) {
59 # TODO fzf-select which of the records the user (ahem, me) wants.
60 printf "[WARNING] Found more than one record.\n" > "/dev/stderr"
61 exit 0
62 }
63 }
64 ' \
65 ~/._p/p \
66 | xsel -i -b -t 30000
67 }
68
69 ## web search
70 ## ws : string -> unit
71 ws() {
72 local line search_string0 search_string
73
74 search_string0="$*"
75 case "$search_string0" in
76 '')
77 while read -r line; do
78 search_string="${search_string} ${line}"
79 done;;
80 *)
81 search_string="$search_string0";;
82 esac
83
84 firefox --search "$search_string"
85 }
86
87
88 ## dictionary
89 ## d : string -> string list
90 d() {
91 local -r word=$(fzf < /usr/share/dict/words)
92 dict "$word"
93 }
94
95 ## shell_activity_report : (mon | dow) -> string list
96 shell_activity_report() {
97 # TODO: optional concrete number output
98 # TODO: optional combinations of granularities: hour, weekday, month, year
99 local group_by="$1"
100 case "$group_by" in
101 'mon') ;;
102 'dow') ;;
103 '') group_by='dow';;
104 *)
105 echo "Usage: $0 [mon|dow]" >&2
106 kill -INT $$
107 esac
108 history \
109 | awk -v group_by="$group_by" '
110 function date2dow(y, m, d, _t, _i) {
111 # Contract:
112 # y > 1752, 1 <= m <= 12.
113 # Source:
114 # Sakamoto`s methods
115 # https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto%27s_methods
116 _t[ 0] = 0
117 _t[ 1] = 3
118 _t[ 2] = 2
119 _t[ 3] = 5
120 _t[ 4] = 0
121 _t[ 5] = 3
122 _t[ 6] = 5
123 _t[ 7] = 1
124 _t[ 8] = 4
125 _t[ 9] = 6
126 _t[10] = 2
127 _t[11] = 4
128 y -= m < 3
129 _i = int(y + y/4 - y/100 + y/400 + _t[m - 1] + d) % 7
130 _i = _i == 0 ? 7 : _i # Make Sunday last
131 return _i
132
133 }
134
135 {
136 # NOTE: $2 & $3 are specific to oh-my-zsh history output
137 date = $2
138 time = $3
139 d_fields = split(date, d, "-")
140 t_fields = split(time, t, ":")
141 if (t_fields && d_fields) {
142 # +0 to coerce number from string
143 year = d[1] + 0
144 month = d[2] + 0
145 day = d[3] + 0
146 hour = t[1] + 0
147 dow = date2dow(year, month, day)
148 g = group_by == "mon" ? month : dow # dow is default
149 c = count[g, hour]++
150 }
151 if (c > max)
152 max = c
153 }
154
155 END {
156 w[1] = "Monday"
157 w[2] = "Tuesday"
158 w[3] = "Wednesday"
159 w[4] = "Thursday"
160 w[5] = "Friday"
161 w[6] = "Saturday"
162 w[7] = "Sunday"
163
164 m[ 1] = "January"
165 m[ 2] = "February"
166 m[ 3] = "March"
167 m[ 4] = "April"
168 m[ 5] = "May"
169 m[ 6] = "June"
170 m[ 7] = "July"
171 m[ 8] = "August"
172 m[ 9] = "September"
173 m[10] = "October"
174 m[11] = "November"
175 m[12] = "December"
176
177 n = group_by == "mon" ? 12 : 7 # dow is default
178
179 for (gid = 1; gid <= n; gid++) {
180 group = group_by == "mon" ? m[gid] : w[gid]
181 printf "%s\n", group;
182 for (hour=0; hour<24; hour++) {
183 c = count[gid, hour]
184 printf " %2d ", hour
185 for (i = 1; i <= (c * 100) / max; i++)
186 printf "|"
187 printf "\n"
188 }
189 }
190 }'
191 }
192
193 ## top_commands : unit -> (command:string * count:number * bar:string) list
194 top_commands() {
195 history \
196 | awk '
197 {
198 count[$4]++
199 }
200
201 END {
202 for (cmd in count)
203 print count[cmd], cmd
204 }' \
205 | sort -n -r -k 1 \
206 | head -50 \
207 | awk '
208 {
209 cmd[NR] = $2
210 c = count[NR] = $1 + 0 # + 0 to coerce number from string
211 if (c > max)
212 max = c
213 }
214
215 END {
216 for (i = 1; i <= NR; i++) {
217 c = count[i]
218 printf "%s %d ", cmd[i], c
219 scaled = (c * 100) / max
220 for (j = 1; j <= scaled; j++)
221 printf "|"
222 printf "\n"
223 }
224 }' \
225 | column -t
226 }
227
228 ## Top Disk-Using directories
229 ## TODO: Consider using numfmt instead of awk
230 ## tdu : path-string -> (size:number * directory:path-string) list
231 tdu() {
232 local -r root_path="$1"
233
234 du "$root_path" \
235 | awk '
236 {
237 size = $1
238 path = $0
239 sub("^" $1 "\t+", "", path)
240 paths[path] = size
241 if (size > max)
242 max = size
243 }
244
245 END {
246 for (path in paths) {
247 size = paths[path]
248 pct = 100 * (size / max)
249 gb = size / 1024 / 1024
250 printf("%6.2f %3d%% %s\n", gb, pct, path)
251 }
252 }
253 ' \
254 | sort -r -n -k 1 \
255 | head -50 \
256 | tac
257 # A slight optimization: head can exit before traversing the full input.
258 }
259
260 ## Top Disk-Using Files
261 ## tduf : path-string list -> (size:number * file:path-string) list
262 tduf() {
263 find "$@" -type f -printf '%s\t%p\0' \
264 | sort -z -n -k 1 \
265 | tail -z -n 50 \
266 | gawk -v RS='\0' '
267 {
268 size = $1
269 path = $0
270 sub("^" $1 "\t+", "", path)
271 gb = size / 1024 / 1024 / 1024
272 printf("%f\t%s\n", gb, path)
273 }'
274 }
275
276 # Most-recently modified file system objects
277 ## recent : ?(path-string list) -> path-string list
278 recent() {
279 # NOTES:
280 # - %T+ is a GNU extension;
281 # - gawk is able to split records on \0, while awk cannot.
282 find "$@" -printf '%T@ %T+ %p\0' \
283 | tee >(gawk -v RS='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
284 | sort -z -k 1 -n -r \
285 | head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
286 | gawk -v RS='\0' '
287 {
288 sub("^" $1 " +", "") # Remove epoch time
289 sub("+", " ") # Blank-out the default separator
290 sub("\\.[0-9]+", "") # Remove fractional seconds
291 print
292 }'
293 }
294
295 ## recent_dirs : ?(path-string list) -> path-string list
296 recent_dirs() {
297 recent "$@" -type d
298 }
299
300 ## recent_files : ?(path-string list) -> path-string list
301 recent_files() {
302 recent "$@" -type f
303 }
304
305 ## pa_def_sink : unit -> string
306 pa_def_sink() {
307 pactl info | awk '/^Default Sink:/ {print $3}'
308 }
309
310 ## void_pkgs : ?(string) -> json
311 void_pkgs() {
312 curl "https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq '.data'
313 }
314
315 ## Colorful man
316 ## man : string -> string
317 man() {
318 # mb: begin blink
319 # md: begin bold
320 # me: end bold, blink and underline
321 #
322 # so: begin standout (reverse video)
323 # se: end standout
324 #
325 # us: begin underline
326 # ue: end underline
327
328 LESS_TERMCAP_md=$'\e[01;30m' \
329 LESS_TERMCAP_me=$'\e[0m' \
330 LESS_TERMCAP_so=$'\e[01;44;33m' \
331 LESS_TERMCAP_se=$'\e[0m' \
332 LESS_TERMCAP_us=$'\e[01;33m' \
333 LESS_TERMCAP_ue=$'\e[0m' \
334 command man "$@"
335 }
336
337 ## new experiment
338 ## x : string list -> unit
339 x() {
340 cd "$(~/bin/x $@)" || kill -INT $$
341 }
342
343 ## ocaml repl
344 ## hump : unit -> unit
345 hump() {
346 ledit -l "$(stty size | awk '{print $2}')" ocaml $@
347 }
348
349 ## search howtos
350 ## howto : unit -> string
351 howto() {
352 cat "$(find ~/arc/doc/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
353 }
354
355 _yt() {
356 local -r base_dir="$1"
357 local -r uri="$2"
358 local -r opts="$3"
359
360 local -r yt=youtube-dl
361 local -r id=$("$yt" --get-id "$uri")
362 local -r title=$("$yt" --get-title "$uri" | sed 's/[^А-Яа-яA-Za-z0-9._-]/_/g')
363 local -r dir="${base_dir}/${title}--${id}"
364
365 mkdir -p "$dir"
366 cd "$dir" || kill -INT $$
367 echo "$uri" > 'uri'
368 "$yt" $opts -c --write-all-thumbnails --write-description --write-info-json "$uri"
369 }
370
371 yt_audio() {
372 local -r uri="$1"
373 _yt "${DIR_YOUTUBE_AUDIO}/individual" "$uri" '-f 140'
374 }
375
376 yt_video() {
377 local -r uri="$1"
378 _yt "${DIR_YOUTUBE_VIDEO}/individual" "$uri"
379 }
380
381 gh_fetch_repos() {
382 local -r user_type="$1"
383 local -r user_name="$2"
384
385 curl "https://api.github.com/$user_type/$user_name/repos?page=1&per_page=10000"
386 }
387
388 gh_clone() {
389 local -r gh_user_type="$1"
390 local -r gh_user_name="$2"
391
392 local -r gh_dir="${DIR_GITHUB}/${gh_user_name}"
393 mkdir -p "$gh_dir"
394 cd "$gh_dir" || kill -INT $$
395 gh_fetch_repos "$gh_user_type" "$gh_user_name" \
396 | jq --raw-output '.[] | select(.fork | not) | .clone_url' \
397 | parallel -j 25 \
398 git clone {}
399 }
400
401 gh_clone_user() {
402 gh_clone 'users' "$1"
403 }
404
405 gh_clone_org() {
406 gh_clone 'orgs' "$1"
407 }
408
409 gh_clone_repo() {
410 gh_username=$(echo "$1" | awk -F / '"$1 == "https" && $3 == github.com" {print $4}')
411 gh_dir="${DIR_GITHUB}/${gh_username}"
412 mkdir -p "$gh_dir"
413 cd "$gh_dir" || kill -INT $$
414 git clone "$1"
415 }
416
417 work_log_template() {
418 cat << EOF
419 $(date '+%F %A')
420 ==========
421
422 Morning report
423 --------------
424
425 ### Prev
426
427 ### Curr
428
429 ### Next
430
431 ### Blockers
432
433 Day's notes
434 -----------
435 EOF
436 }
437
438 work_log() {
439 mkdir -p "$DIR_WORK_LOG"
440 local -r file_work_log_today="${DIR_WORK_LOG}/daily-$(date +%F).md"
441 if [ ! -f "$file_work_log_today" ]
442 then
443 work_log_template > "$file_work_log_today"
444 fi
445 vim -c 'set spell' "$file_work_log_today"
446
447 }
448
449 note() {
450 mkdir -p "$DIR_NOTES"
451 vim -c 'set spell' "$DIR_NOTES/$(date +'%Y_%m_%d--%H_%M_%S%z')--$1.md"
452 }
453
454 _bt_devs_infos() {
455 # grep's defintion of a line does not include \r, wile awk's does and
456 # which bluetoothctl outputs
457 awk '/^Device +/ {print $2}' \
458 | xargs -I% sh -c 'echo info % | bluetoothctl' \
459 | awk '/^Device |^\t[A-Z][A-Za-z0-9]+: /'
460 }
461
462 bt_devs_paired() {
463 echo 'paired-devices' | bluetoothctl | _bt_devs_infos
464 }
465
466 bt_devs() {
467 echo 'devices' | bluetoothctl | _bt_devs_infos
468 }
469
470 run() {
471 local -r stderr="$(mktemp)"
472
473 local code urgency
474
475 $@ 2> >(tee "$stderr")
476 code="$?"
477 case "$code" in
478 0) urgency='normal';;
479 *) urgency='critical'
480 esac
481 notify-send -u "$urgency" "Job done: $code" "$(cat $stderr)"
482 rm "$stderr"
483 }
484
485 bar_gauge() {
486 awk "$@" '
487 BEGIN {
488 # CLI options
489 width = width ? width : 80
490 ch_left = ch_left ? ch_left : "["
491 ch_right = ch_right ? ch_right : "]"
492 ch_blank = ch_blank ? ch_blank : "-"
493 ch_used = ch_used ? ch_used : "|"
494 num = num ? 1 : 0
495 pct = pct ? 1 : 0
496 }
497
498 {
499 cur = $1
500 max = $2
501 lab = $3
502
503 cur_scaled = num_scale(cur, max, 1, width)
504
505 printf \
506 "%s%s%s%s", \
507 lab ? lab " " : "", \
508 num ? cur "/" max " " : "", \
509 pct ? sprintf("%3.0f%% ", cur / max * 100) : "", \
510 ch_left
511 for (i=1; i<=width; i++) {
512 c = i <= cur_scaled ? ch_used : ch_blank
513 printf "%s", c
514 }
515 printf "%s\n", ch_right
516 }
517
518 function num_scale(src_cur, src_max, dst_min, dst_max) {
519 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
520 }
521 '
522 }
523
524 flat_top_5() {
525 sort -n -k 1 -r \
526 | head -5 \
527 | awk '
528 {
529 cur = $1
530 max = $2
531 name = $3
532 pct = cur / max * 100
533 printf "%s%s %.2f%%", sep, name, pct
534 sep = ", "
535 }
536
537 END {printf "\n"}
538 '
539 }
540
541 internet_addr() {
542 curl --silent --show-error --max-time "${1:=1}" 'https://api.ipify.org' 2>&1
543 }
544
545 status_batt() {
546 case "$(uname)" in
547 'Linux')
548 if which upower > /dev/null
549 then
550 upower --dump \
551 | awk '
552 /^Device:[ \t]+/ {
553 device["path"] = $2
554 next
555 }
556
557 / battery/ && device["path"] {
558 device["is_battery"] = 1
559 next
560 }
561
562 / percentage:/ && device["is_battery"] {
563 device["battery_percentage"] = $2
564 sub("%$", "", device["battery_percentage"])
565 next
566 }
567
568 /^$/ {
569 if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice")
570 print device["battery_percentage"], 100, "batt"
571 delete device
572 }
573 '
574 fi
575 ;;
576 esac
577 }
578
579 indent() {
580 awk -v unit="$1" '{printf "%s%s\n", unit, $0}'
581 }
582
583 status() {
584 local -r indent_unit=' '
585
586 uname -srvmo
587 hostname | figlet
588 uptime
589
590 echo
591
592 echo 'accounting'
593
594 printf '%stmux\n%ssessions %d, clients %d\n' \
595 "$indent_unit" \
596 "${indent_unit}${indent_unit}" \
597 "$(tmux list-sessions 2> /dev/null | wc -l)" \
598 "$(tmux list-clients 2> /dev/null | wc -l)"
599
600 echo
601
602 printf '%sprocs by user\n' "${indent_unit}"
603 ps -eo user \
604 | awk '
605 NR > 1 {
606 count_by_user[$1]++
607 total++
608 }
609
610 END {
611 for (user in count_by_user)
612 print count_by_user[user], total, user
613 }
614 ' \
615 | flat_top_5 \
616 | indent "${indent_unit}${indent_unit}"
617
618 echo
619
620 echo 'resources'
621 (
622 free | awk '$1 == "Mem:" {print $3, $2, "mem"}'
623 df ~ | awk 'NR == 2 {print $3, $3 + $4, "disk"}'
624 status_batt
625 ) \
626 | bar_gauge -v width=60 -v pct=1 \
627 | column -t \
628 | indent "$indent_unit"
629
630 echo
631
632 printf '%smem by proc\n' "$indent_unit"
633 ps -eo rss,comm \
634 | awk -v total="$(free | awk '$1 == "Mem:" {print $2; exit}')" '
635 NR > 1 {
636 rss = $1
637 proc = $2
638 by_proc[proc] += rss
639 }
640
641 END {
642 for (proc in by_proc)
643 print by_proc[proc], total, proc
644 }
645 ' \
646 | flat_top_5 \
647 | indent "${indent_unit}${indent_unit}"
648
649 echo
650
651 local _dir temp_input label_file label
652
653 printf '%sthermal\n' "$indent_unit"
654 for _dir in /sys/class/hwmon/hwmon*; do
655 cat "$_dir"/name
656 find "$_dir"/ -name 'temp*_input' \
657 | while read -r temp_input; do
658 label_file=${temp_input//_input/_label}
659 if [ -f "$label_file" ]; then
660 label=$(< "$label_file")
661 else
662 label=''
663 fi
664 awk -v label="$label" '{
665 if (label)
666 label = sprintf(" (%s)", label)
667 printf("%.2f°C%s\n", $1 / 1000, label)
668 }' \
669 "$temp_input"
670 done \
671 | sort \
672 | indent "$indent_unit"
673 done \
674 | indent "${indent_unit}${indent_unit}"
675
676 echo 'net'
677 #local -r internet_addr=$(internet_addr 0.5)
678 #local -r internet_ptr=$(host -W 1 "$internet_addr" | awk 'NR == 1 {print $NF}' )
679
680 #echo "${indent_unit}internet"
681 #echo "${indent_unit}${indent_unit}$internet_addr $internet_ptr"
682 echo "${indent_unit}if"
683 (ifconfig; iwconfig) 2> /dev/null \
684 | awk '
685 /^[^ ]/ {
686 device = $1
687 sub(":$", "", device)
688 if ($4 ~ "ESSID:") {
689 _essid = $4
690 sub("^ESSID:\"", "", _essid)
691 sub("\"$", "", _essid)
692 essid[device] = _essid
693 }
694 next
695 }
696
697 /^ / && $1 == "inet" {
698 address[device] = $2
699 next
700 }
701
702 /^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ {
703 split($2, lq_parts_eq, "=")
704 split(lq_parts_eq[2], lq_parts_slash, "/")
705 cur = lq_parts_slash[1]
706 max = lq_parts_slash[2]
707 link[device] = cur / max * 100
708 next
709 }
710
711 END {
712 for (device in address)
713 if (device != "lo") {
714 l = link[device]
715 e = essid[device]
716 l = l ? sprintf("%.0f%%", l) : "--"
717 e = e ? e : "--"
718 print device, address[device], e, l
719 }
720 }
721 ' \
722 | column -t \
723 | indent "${indent_unit}${indent_unit}"
724
725 # WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
726
727 echo "${indent_unit}-->"
728
729 sudo -n netstat -tulnp \
730 | awk -v indent="${indent_unit}${indent_unit}" '
731 NR > 2 && ((/^tcp/ && proc = $7) || (/^udp/ && proc = $6)) {
732 protocol = $1
733 addr = $4
734 port = a[split(addr, a, ":")]
735 name = p[split(proc, p, "/")]
736 names[name] = 1
737 protocols[protocol] = 1
738 if (!seen[protocol, name, port]++)
739 ports[protocol, name, ++seen[protocol, name]] = port
740 }
741
742 END {
743 for (protocol in protocols) {
744 printf "%s%s\t", indent, toupper(protocol)
745 for (name in names) {
746 if (n = seen[protocol, name]) {
747 sep = ""
748 printf "%s:", name
749 for (i = 1; i <= n; i++) {
750 printf "%s%d", sep, ports[protocol, name, i]
751 sep = ","
752 }
753 printf " "
754 }
755 }
756 printf "\n"
757 }
758 }'
759
760 echo "${indent_unit}<->"
761
762 printf '%sTCP\t' "${indent_unit}${indent_unit}"
763 sudo -n netstat -tnp \
764 | awk 'NR > 2 && $6 == "ESTABLISHED" {print $7}' \
765 | awk '{sub("^[0-9]+/", ""); print}' \
766 | sort -u \
767 | xargs \
768 | column -t
769
770 # TODO: iptables summary
771 }
772
773 ssh_invalid_by_addr() {
774 awk '
775 /: Invalid user/ && $5 ~ /^sshd/ {
776 addr=$10 == "port" ? $9 : $10
777 max++
778 by_addr[addr]++
779 }
780
781 END {
782 for (addr in by_addr)
783 if ((c = by_addr[addr]) > 1)
784 printf "%d %d %s\n", c, max, addr
785 }
786 ' \
787 /var/log/auth.log \
788 /var/log/auth.log.1 \
789 | sort -n -k 1 \
790 | bar_gauge -v width="$(stty size | awk '{print $2}')" -v num=1 -v ch_right=' ' -v ch_left=' ' -v ch_blank=' ' \
791 | column -t
792 }
793
794 ssh_invalid_by_day() {
795 awk '
796 BEGIN {
797 m["Jan"] = "01"
798 m["Feb"] = "02"
799 m["Mar"] = "03"
800 m["Apr"] = "04"
801 m["May"] = "05"
802 m["Jun"] = "06"
803 m["Jul"] = "07"
804 m["Aug"] = "08"
805 m["Sep"] = "09"
806 m["Oct"] = "10"
807 m["Nov"] = "11"
808 m["Dec"] = "12"
809 }
810
811 /: Invalid user/ && $5 ~ /^sshd/ {
812 day = m[$1] "-" $2
813 max++
814 by_day[day]++
815 }
816
817 END {
818 for (day in by_day)
819 if ((c = by_day[day]) > 1)
820 printf "%d %d %s\n", c, max, day
821 }
822 ' \
823 /var/log/auth.log \
824 /var/log/auth.log.1 \
825 | sort -k 3 \
826 | bar_gauge -v width="$(stty size | awk '{print $2}')" -v num=1 -v ch_right=' ' -v ch_left=' ' -v ch_blank=' ' \
827 | column -t
828 }
829
830 ssh_invalid_by_user() {
831 awk '
832 /: Invalid user/ && $5 ~ /^sshd/ {
833 user=$8
834 max++
835 by_user[user]++
836 }
837
838 END {
839 for (user in by_user)
840 if ((c = by_user[user]) > 1)
841 printf "%d %d %s\n", c, max, user
842 }
843 ' \
844 /var/log/auth.log \
845 /var/log/auth.log.1 \
846 | sort -n -k 1 \
847 | bar_gauge -v width="$(stty size | awk '{print $2}')" -v num=1 -v ch_right=' ' -v ch_left=' ' -v ch_blank=' ' \
848 | column -t
849 }
850
851 loggers() {
852 awk '
853 {
854 split($5, prog, "[")
855 sub(":$", "", prog[1]) # if there were no [], than : will is left behind
856 print prog[1]
857 }' /var/log/syslog /var/log/syslog.1 \
858 | awk '
859 {
860 n = split($1, path, "/") # prog may be in path form
861 prog = path[n]
862 total++
863 count[prog]++
864 }
865
866 END {
867 for (prog in count)
868 print count[prog], total, prog
869 }' \
870 | sort -n -k 1 \
871 | bar_gauge -v num=1 -v ch_right=' ' -v ch_left=' ' -v ch_blank=' ' \
872 | column -t
873 }
This page took 0.129898 seconds and 3 git commands to generate.