forked from Droogans/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kubgrep.sh
executable file
·42 lines (35 loc) · 975 Bytes
/
kubgrep.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
__term="${1?Usage: TERM}"
__logs="/tmp/kubgrep-${__term}.log"
trap sortlogs INT
sortlogs () {
echo "Sorting all logs streamed to $__logs"
sort "$__logs" -o "$__logs"
$EDITOR --no-wait "$__logs"
}
__include=("-i" "$__term")
__exclude=("-e" "- DEBUG -|aiohttp.access")
__since=("-s" "2h")
__template=("--template" "{{.Namespace}}{{.Message}}")
args=()
for arg in "${@:2}"; do
case "$arg" in
-i|--include)
__include=()
;;
-e|--exclude)
__exclude=()
;;
-s|--since)
__since=()
;;
--template)
__template=()
;;
esac
__args+=("$arg")
done
function __ts_sort() {
sed -E 's/^(.+)?([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{5})([0-9]+)?Z/\2Z \1/' <&0
}
stern "$__term" "${__args[@]}" "${__include[@]}" "${__exclude[@]}" "${__since[@]}" "${__template[@]}" -t -o raw | tee >(__ts_sort > "$__logs") | __ts_sort