Dmesg mit korrektem lesbaren Timestamp: Unterschied zwischen den Versionen

Aus Si:Wiki von Siegrist SystemLösungen - Informatik und Rezepte
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: « Die Zeitstempel vom <code>dmesg</code> sind die Sekunden.Millisekunden seit dem letzen Boot. Für Menschen eigentlich unlesbar bis nutzlos.<br> Kommt hinzu, das…»)
 
K
Zeile 17: Zeile 17:
  
 
# pipe dmesg output through a Perl snippet to convert it's timestamp to correct readable times
 
# pipe dmesg output through a Perl snippet to convert it's timestamp to correct readable times
#dmesg | perl -pe 'BEGIN{$offset=shift} s/^\[\s*(\d+)\S+/localtime($1+$offset)/e' $offset
+
# for use without colors:
# or use this instead to keep dmesg colors
+
###dmesg | perl -pe 'BEGIN{$offset=shift} s/^\[\s*(\d+)\S+/localtime($1+$offset)/e' $offset
 +
# for use to keep dmesg colors:
 
dmesg --color=always | perl -pe 'BEGIN{$offset=shift} s/^(\x1b\[.*?m)?\[\s*(\d+)\S+/$1.localtime($2+$offset)/e' $offset
 
dmesg --color=always | perl -pe 'BEGIN{$offset=shift} s/^(\x1b\[.*?m)?\[\s*(\d+)\S+/$1.localtime($2+$offset)/e' $offset
  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
<br>
 +
: Je nach System die dmesg-Zeile mit oder ohne 'color' aktivieren !<br>
 
<br>
 
<br>

Version vom 4. März 2021, 13:43 Uhr

Die Zeitstempel vom dmesg sind die Sekunden.Millisekunden seit dem letzen Boot. Für Menschen eigentlich unlesbar bis nutzlos.
Kommt hinzu, dass diese Zeitstempel nach einem suspend/resume nicht mehr stimmen da sie währendessen nicht gezählt werden.

Dieses Skript ( etwas angepasst von https://serverfault.com/users/63361/mivk , danke ) konvertiert die Timestamp zu menschenlesbaren und korrekten Zeiteinträgen.


#!/bin/bash
#
 
# write current time to kernel ring buffer
echo "timecheck: $(date +%s) = $(date +%F_%T)" >  /dev/kmsg
 
# use our "timecheck" entry to get the difference
offset=$(dmesg | grep timecheck | tail -1 | perl -nle '($t1,$t2)=/^.(\d+)\S+ timecheck: (\d+)/; print $t2-$t1')
 
# pipe dmesg output through a Perl snippet to convert it's timestamp to correct readable times
# for use without colors:
###dmesg | perl -pe 'BEGIN{$offset=shift} s/^\[\s*(\d+)\S+/localtime($1+$offset)/e' $offset
# for use to keep dmesg colors:
dmesg --color=always | perl -pe 'BEGIN{$offset=shift} s/^(\x1b\[.*?m)?\[\s*(\d+)\S+/$1.localtime($2+$offset)/e' $offset


Je nach System die dmesg-Zeile mit oder ohne 'color' aktivieren !