GREP_COLORS – change the colors in the GREP output.

Today we will look at the variable GREP_COLORS. This variable determines the colour that is used with the grep command. You can look at the man page of the grep command to see what the various options mean. Here is the excerpt from the man command:

    GREP_COLORS
              Specifies the colors and other attributes used to highlight various  parts  of  the
              output.   Its  value  is  a  colon-separated  list of capabilities that defaults to
              ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36  with  the  rv  and  ne   boolean
              capabilities omitted (i.e., false).  Supported capabilities are as follows.

              sl=    SGR  substring  for  whole  selected lines (i.e., matching lines when the -v
                     command-line option is omitted, or non-matching lines when -v is specified).
                     If however the boolean rv capability and the -v command-line option are both
                     specified, it applies to context matching lines  instead.   The  default  is
                     empty (i.e., the terminal's default color pair).

              cx=    SGR  substring for whole context lines (i.e., non-matching lines when the -v
                     command-line option is omitted, or matching lines when -v is specified).  If
                     however  the  boolean  rv capability and the -v command-line option are both
                     specified, it applies to selected non-matching lines instead.   The  default
                     is empty (i.e., the terminal's default color pair).

              rv     Boolean  value  that  reverses  (swaps)  the  meanings  of  the  sl= and cx=
                     capabilities when the -v command-line option is specified.  The  default  is
                     false (i.e., the capability is omitted).

              mt=01;31
                     SGR  substring  for  matching  non-empty  text in any matching line (i.e., a
                     selected line when the -v command-line option is omitted, or a context  line
                     when  -v  is specified).  Setting this is equivalent to setting both ms= and
                     mc= at once to the same value.  The default is a bold  red  text  foreground
                     over the current line background.

              ms=01;31
                     SGR substring for matching non-empty text in a selected line.  (This is only
                     used when the -v command-line option is omitted.)  The effect of the sl= (or
                     cx=  if  rv) capability remains active when this kicks in.  The default is a
                     bold red text foreground over the current line background.

              mc=01;31
                     SGR substring for matching non-empty text in a context line.  (This is  only
                     used  when  the -v command-line option is specified.)  The effect of the cx=
                     (or sl= if rv) capability remains active when this kicks in.  The default is
                     a bold red text foreground over the current line background.

              fn=35  SGR  substring  for file names prefixing any content line.  The default is a
                     magenta text foreground over the terminal's default background.

              ln=32  SGR substring for line numbers prefixing any content line.  The default is a
                     green text foreground over the terminal's default background.

              bn=32  SGR substring for byte offsets prefixing any content line.  The default is a
                     green text foreground over the terminal's default background.

              se=36  SGR substring for separators that are inserted between selected line  fields
                     (:),  between context line fields, (-), and between groups of adjacent lines
                     when nonzero context  is  specified  (--).   The  default  is  a  cyan  text
                     foreground over the terminal's default background.

              ne     Boolean  value that prevents clearing to the end of line using Erase in Line
                     (EL) to Right (\33[K) each time a colorized item ends.  This  is  needed  on
                     terminals on which EL is not supported.  It is otherwise useful on terminals
                     for which the back_color_erase (bce) boolean terminfo  capability  does  not
                     apply,  when  the  chosen  highlight colors do not affect the background, or
                     when EL is too slow or causes too much flicker.  The default is false (i.e.,
                     the capability is omitted).

Now time for some examples:

1) With GREP_OPTIONS set to “”

1
export GREP_OPTIONS=

 

grep color options
grep color options

2) with the following set:

1
export GREP_COLORS="fn=34:mc=01;30:ms=33:sl=21:cx=31"

 

grep color options
grep color options

3) and just the colour for filename and match:

1
export GREP_COLORS="mc=00;36:ms=31:mt=01;38"

 

grep color options
grep color options

4) Slightly lighter colour:

1
export GREP_COLORS="mc=00;36:ms=31:mt=01;33"

 

grep color options
grep color options

5) Default colour for line numbers:

 

grep color options
grep color options

6) Line number colour:

1
export GREP_COLORS="mc=00;36:ms=31:mt=01;38:ln=31"

 

grep color options
grep color options

Hope you will put some colour to grep.

 

22/Apr/2019 : Edit – There is one more very useful article that you should check out – https://www.jenreviews.com/color-meaning/

Enhanced by Zemanta

bash debug – log all executed commands

Screenshot of a Bash 3.1 session demonstrating...
Screenshot of a Bash 3.1 session demonstrating its particularities. Shows exporting a variable, alias, type, Bash’s kill, environment variables PS1, BASH_VERSION and SHELLOPTS, redirecting standard output and standard error and history expansion. A POSIX session is launched from a normal session. Finally, the POSIX session kills itself (since just “exit” would be too boring). (Photo credit: Wikipedia)

Whenever I am writing a script in perl or bash, I always wish that there
was some way to have all the commands logged or output to screen. I know
there is “set -x” option to have debugging enabled, but sometimes that
seems to be too much information and I dont really need all that. So, here
is something I found recently for bash to log all the executed commands.

trap "echo $BASH_COMMAND" DEBUG

This will echo/print all the commands on the stdout.

 

Enhanced by Zemanta

Monitor your system with sysusage.

First some information on sysusage:

Description :
SysUsage continuously monitor your systems informations and generate
periodical graph reports using rrdtool or javascript jqplot library.
All reports are shown throught a web interface.

SysUsage grabs all system activities using Sar and system commands allowing
you to keep tracks of your computer or server activity during his life.
It is a great help for performance analysis and resources management. The
threshold notification can alarm you when the system capabilities are
reached by sending SMTP messages or throught Nagios reports.

By default it will monitor all you need to know on your server activity, it
is written in Perl and should works on all Unix like plateforms. It doesn’t
require a Database system like MySQL or PostgreSQL but lie on rrdtool. In
addition you can embeded your own plugins written in any programing language.

Since release 5.0 SysUsage can be run from a centralized place where
collected statistics will be stored and where graphics will be rendered.
Unless other monitoring tools with lot of administration work, SysUsage is
design to have the lesspossible things to configure and a high level of admin
system knowledge. Each server can also be self monitored and you just have to
connect your browser to the web interface to know his health level.

SysUsage is design with simplicity in mind. I want all relevant statistics
from my servers within an intuitive web interface and without spending too
much time to configure it, if you know Nagios, you know what I mean. You will
especially like SysUsage for that.

And now for the installation:

sudo yum install sysusage sysusage-httpd

Once you have installed, you would need to enable the crontab to collect the data. And the sysusage-httpd is for the apache server configure to enable you to access http://localhost/sysusage

And you are done. It pretty good to see the overall system usage wrt to CPU, Disk and network.

Enhanced by Zemanta