-
Notifications
You must be signed in to change notification settings - Fork 11
/
dmesgt
executable file
·38 lines (31 loc) · 937 Bytes
/
dmesgt
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
#!/bin/bash
#
# Code from https://stackoverflow.com/a/36361197/4640820 by Allen Belletti
# based itself on code from https://stackoverflow.com/a/19272272/4640820 by Lucas Cimon
#
help() {
echo 'usage: dmesgt'
echo ' dmesgt --help'
echo
echo ' Output dmesg with not broken timestamps.'
echo
exit 1
}
[ "$1" == "--help" ] && help
set -e # stop on error
set -u # stop on undefined variable
set -o pipefail # stop part of pipeline failing
FORMAT="%a %b %d %H:%M:%S %Y"
now=$(date +%s)
cputime_line=$(grep -m1 "\.clock" /proc/sched_debug)
if [[ $cputime_line =~ [^0-9]*([0-9]*).* ]]; then
cputime=$((BASH_REMATCH[1] / 1000))
fi
dmesg | while IFS= read -r line; do
if [[ $line =~ ^\[\ *([0-9]+)\.[0-9]+\]\ (.*) ]]; then
stamp=$((now-cputime+BASH_REMATCH[1]))
echo "[$(date +"${FORMAT}" --date=@${stamp})] ${BASH_REMATCH[2]}"
else
echo "$line"
fi
done