-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiff-kernel-logs
More file actions
executable file
·75 lines (62 loc) · 1.13 KB
/
diff-kernel-logs
File metadata and controls
executable file
·75 lines (62 loc) · 1.13 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash -eu
#
# Diff two kernel logs
#
function filter()
{
local infile=${1}
python3 -c "
import re
import sys
with open('${infile}') as fh:
for line in fh:
line = line.strip()
line = re.sub(r'^\[[^\]]+\] ', '', line)
line = re.sub(r'\d+ MB/', 'xxx MB/', line)
print(line)
"
}
function usage()
{
cat <<EOF
Usage: $(basename "${0}") [-h] [-s] INFILE1 INFILE2
Diff two kernel logs (dmesg).
Optinal arguments:
-h, --help Show this help text and exit.
-s, --sort Sort the logs before the diff.
EOF
}
p="cat"
infile1=
infile2=
while [ ${#} -ne 0 ] ; do
case "${1}" in
-h|--help)
usage
exit
;;
-s|--sort)
p="sort"
;;
*)
if [ -z "${infile1}" ] ; then
infile1=${1}
elif [ -z "${infile2}" ] ; then
infile2=${1}
else
echo "Invalid argument: ${1}" >&2
exit 2
fi
;;
esac
shift
done
if [ -z "${infile1}" ] || [ -z "${infile2}" ] ; then
usage
exit 2
fi
trap "rm -f /tmp/.{1,2}" INT TERM EXIT HUP
filter "${infile1}" | "${p}" > /tmp/.1
filter "${infile2}" | "${p}" > /tmp/.2
colordiff -y -W "$(tput cols)" /tmp/.1 /tmp/.2 || true
rm -f /tmp/.1 /tmp/.2