Color your process listings

Many a times I am grepping for a process that is running on a prod server with lots of different configuration parameters. However, since there are so many of them, it is very difficult to view a particular parameter itself and find out what value was assigned to it. I wanted to make it easier on the eyes and decided to color code the parameters and separate them out from the values. Here’s the bash function I pulled out.

colorme()
{
  gawk 'BEGIN {RS=" --| -"; }{print $0}' \
  | sed -e 's/\([[:alpha:]]\+\)=/\1 /g' \
  | gawk 'BEGIN    {printf "-----------------\n" ; }
            {
                if (NF > 2) printf "\n\033[41;5;1m%s\033[0m\n", $NF ;
                printf "\033[40;38;5;82m  %30s  \033[38;5;198m %s \033[0m \n", $1, $2
            }'
}

The idea is as follows:

Here is a sample command I wanted to test out.

/opt/py27env/bin/python manage.py main-service-name --daemonize \
    --alias-svc=mainsvc01 --application-id=app03/mainsvc01 --monitoring-service-name=mainsvc01 \
    --log-level=DEBUG --solace-session-prop-host=server.prod --solace-session-prop-username=testing \
    --solace-session-prop-password=testing --solace-session-prop-vpn=testing \
    --solace-session-prop-cache-name=test_dc \
    --rate=10

Here is the result from my tests:

Color coded process listing

Color coded process listing

comments powered by Disqus