From Mageia wiki
Revision as of 10:58, 27 January 2018 by Dvgevers (talk | contribs) (readability)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


dmesg (upto Mageia 6) and comparable content from journalctl (as of Mageia 7)

This paragraph applies to Mageia upto 6 and Cauldron until December 2017.


Nearly every user with a little experience using Linux will know the file in /var/log called 'dmesg'.

As per 'man dmesg' it will "print or control the kernel ring buffer"

For examples and options, please read man dmesg.

At each new boot up of your machine, the previous /var/log/dmesg gets saved as /var/log/dmesg.old and a new 'dmesg' is created.

For reasons of curiosity, bug hunting, or any other need to compare, one might like to see the difference between the old and the new dmesg.

But each line starts with a pair of square brackets and numbers in between. This makes comparison ('diff' command) uneasy.

But to still do so, we create a temporary set of files without the numbers and compare those (throwing them away right after):

 #!/usr/bin/bash
 # compare dmesg and dmesg.old without regard to the numbers at the start of each line (c) dvg (at) mageia.org 2013 04 07
 
 cd /var/log
 
 cat dmesg |cut -b 15- >/tmp/dmesg.c
 
 cat dmesg.old |cut -b 15- >/tmp/dmesg.oldc
 
 diff /tmp/dmesg.c /tmp/dmesg.oldc
 
 rm /tmp/dmesg.c /tmp/dmesg.oldc


Please save this script by any name and put it in your $PATH, for example call it compare-new-and-old-dmesg.sh and save it in /usr/local/bin with octal number 700 (ownership, readable, writable and executable by root).

It will print the output on your console or terminal. If you need it to save to a file, just add to the penultimate line: ' >/tmp/anyfile'


Paragraph for current Cauldron (Mageia 7) - Comparable information from the "journalctl -k" command as of systemd 236-2.


For reasons as above, but lacking files /var/log/dmesg* we may want to look at "dmesg" like content of journalctl and we need to adjust the script for the new setup of systemd:

 #!/usr/bin/bash
 #
 # Script to compare dmesg from current boot and dmesg from previous boot without regard to the numbers 
 # at the start of each line.  (c) dvg (at) mageia.org 2013 04 07
 # revised for systemd 236-2, 2018 01 27
 # Note that the dmesg lines containing audit and shorewall(6) info are ignored here.
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 #
 # 
 THIS SCRIPT NEEDS ADJUSTMENT BEFORE IT IS SAVED TO YOUR MACHINE: 1. delete or comment current line and
 # 2. follow instructions in lines starting with "###" and save the script to path, for example to /usr/local/bin
 
 cd /tmp
 
 journalctl -k --boot=0 >dmesgb-0
 
 journalctl -k --boot=-1 >dmesgb-1
 
 
 ###  Execute the command "journalctl -k |tail" and observe ten lines each starting in the format:
 ###  Jan 27 08:43:14 my.hostname kernel:
 ###  Now count the number of positions from first until the colon (:). In the above example: 35.
 ###  In the next 2 lines of script replace '35' by the number you have just found:
 
 
 cat dmesgb-0 |cut -b 35- >/tmp/dmesgb-0.c
 
 cat dmesgb-1 |cut -b 35- >/tmp/dmesgb-1.c
 
 ###  Before finishing this script, give the command:
 ###  grep LOGFO /etc/shorew*/shorew*
 ###  Let's assume your output reads:
 ###  /etc/shorewall6/shorewall6.conf:LOGFORMAT="Swl6:%s:%s:"
 ###  /etc/shorewall/shorewall.conf:LOGFORMAT="Swll:%s:%s:"
 ###
 ###  Based on the result we take the first syllable between quotes and add it in the next line "diff..."
 ###       (in my example "Swl6" and "Swll"):
 
 
 diff /tmp/dmesgb-0.c /tmp/dmesgb-1.c |grep -v Swl6 |grep -v Swll |grep -v audit
 
 rm /tmp/dmesg*
 
 ###  This script will print the comparison to STDOUT. If output needs to be saved add after the word "audit": 
 ###  >/tmp/anyname.txt
 ###  on the same line, without the '###"