{"id":210,"date":"2019-01-02T20:46:36","date_gmt":"2019-01-02T19:46:36","guid":{"rendered":"http:\/\/linuxboxen2.dk\/?p=210"},"modified":"2019-01-02T20:46:36","modified_gmt":"2019-01-02T19:46:36","slug":"saadan-haandteres-dmesg-timestamps","status":"publish","type":"post","link":"https:\/\/www.linuxboxen.dk\/?p=210","title":{"rendered":"S\u00e5dan h\u00e5ndteres dmesg timestamps"},"content":{"rendered":"\n<p>Ved en dmesg kan du se logs fra kernel. Der kan du ikke se tids stemple.<\/p>\n<pre><code>$ dmesg<\/code><\/pre>\n<pre>[4248617.618064] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:0d:8f:41:08:00 SRC=176.119.4.49 DST=139.162.207.23 LEN=40 TOS=0x00 PREC=0x00 TTL=247 ID=22103 PROTO=TCP SPT=40689 DPT=22670 WINDOW=1024 RES=0x00 SYN URGP=0\n[4248634.528232] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:5a:1a:41:08:00 SRC=198.108.67.54 DST=139.162.207.23 LEN=40 TOS=0x00 PREC=0x00 TTL=38 ID=36568 PROTO=TCP SPT=57194 DPT=1029 WINDOW=1024 RES=0x00 SYN URGP=0\n[4248671.839504] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:5a:1a:41:08:00 SRC=185.153.198.208 DST=139.162.207.23 LEN=40 TOS=0x08 PREC=0x20 TTL=240\n\nMen hvis du bruger dmest -T s\u00e5 skriver den det som normal dato tid.\n\n<code>$ dmest -T<\/code> [Thu Dec 13 09:16:41 2018] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:0d:8f:41:08:00 SRC=194.55.142.100 DST=139.162.207.23 LEN=40 TOS=0x08 PREC=0x20 TTL=243 ID=34488 PROTO=TCP SPT=59536 DPT=7600 WINDOW=1024 RES=0x00 SYN URGP=0 [Thu Dec 13 09:17:08 2018] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:5a:1a:41:08:00 SRC=37.49.231.179 DST=139.162.207.23 LEN=443 TOS=0x08 PREC=0x20 TTL=55 ID=37784 DF PROTO=UDP SPT=5114 DPT=5060 LEN=423 [Thu Dec 13 09:17:21 2018] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:0d:8f:41:08:00 SRC=185.153.198.206 DST=139.162.207.23 LEN=40 TOS=0x08 PREC=0x20 TTL=240 ID=54321 PROTO=TCP SPT=42417 DPT=8555 WINDOW=65535 RES=0x00 SYN URGP=0<\/pre>\n<p>Det er ikke p\u00e5 alle Linux systemer du kan bruge -T s\u00e5 her er et script som giver samme funktion.<\/p>\n<pre data-copyid=\"3\"><code>\n#!\/bin\/bash\n\n# Translate dmesg timestamps to human readable format\n\n# desired date format\ndate_format=\"%a %b %d %T %Y\"\n\n# uptime in seconds\nuptime=$(cut -d \" \" -f 1 \/proc\/uptime)\n\n# run only if timestamps are enabled\nif [ \"Y\" = \"$(cat \/sys\/module\/printk\/parameters\/time)\" ]; then\n  dmesg | sed \"s\/^\\[[ ]*\\?\\([0-9.]*\\)\\] \\(.*\\)\/\\\\1 \\\\2\/\" | while read timestamp message; do\n    printf \"[%s] %s\\n\" \"$(date --date \"now - $uptime seconds + $timestamp seconds\" +\"${date_format}\")\" \"$message\"\n  done\nelse\n  echo \"Timestamps are disabled (\/sys\/module\/printk\/parameters\/time)\"\nfi<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ved en dmesg kan du se logs fra kernel. Der kan du ikke se tids stemple. $ dmesg [4248617.618064] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:0d:8f:41:08:00 SRC=176.119.4.49 DST=139.162.207.23 LEN=40 TOS=0x00 PREC=0x00 TTL=247 ID=22103 PROTO=TCP SPT=40689 DPT=22670 WINDOW=1024 RES=0x00 SYN URGP=0 [4248634.528232] [UFW BLOCK] IN=eth0 OUT= MAC=f2:3c:91:16:52:96:84:78:ac:5a:1a:41:08:00 SRC=198.108.67.54 DST=139.162.207.23 LEN=40 TOS=0x00 PREC=0x00 TTL=38 ID=36568 PROTO=TCP SPT=57194 DPT=1029 WINDOW=1024 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","footnotes":""},"categories":[2],"tags":[],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-tips"],"_links":{"self":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=210"}],"version-history":[{"count":0,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/posts\/210\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}