ANSI to colorize logs

Ansi color revival to analyze logs

    Example1:

Show in blue the lines containing “[sd” showing everything else and without repeating the same line. (In this example USB sticks)

dmesg| awk '/\[sd/ {print "\33[34m" $0 "\33[39m";next}1'

    Example2

Show green lines when something is added to udev and red when it is removed:


cat /var/log/udev |awk ' /add/{ print "\33[32m" $0 "\33[39m"} /remove/{print "\33[31m" $0 "\33[39m"}'

The colors follow the ANSI color table.
31 is red
32 is green
33 is yellow but I’m not using it as a color, I’m using \33 and it is the scape character.
34 is blue
39 is white

Using 41 instead of 31 is like using a red Stabilo marker.
they can me mixed. example \33[1;31;43m and \33[0;39;40m

http://en.wikipedia.org/wiki/ANSI_escape_code

Never use ANSI coloring with logs conected to the internet or unknown users as a priveleged user. ANSI can be used to change keymaps to run commands (ej: the enter key, the up arrow key… to rm -rf /* )
This is not a new security issue and has been used and abused since de BBS era/ 80’s).

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s