bash

Highlight text on the fly thanks to terminfo and sed.

A colleague today was looking for a way to pipe something to a command that highlights particular strings of text, keeping intact the stdin, similar to what you can see on some modern distros, ie Gentoo.

Grep is not the way as it only prints the lines which contain the pattern that we are looking for.

While there are a bunch of tools that can do that, like supercat, etc. I felt no need to install additional packages for something you can do with few lines of bash and knowing terminal capabilities.

Therefore I wrote this small script, put it in the PATH env variable. The script uses sed and makes use of the terminfo database and of the terminal capabilities to color the text, here it is in case you find it useful:

#!/bin/bash

red=$(tput bold;tput setaf 1)
normal=$(tput sgr0)

while read line; do
  echo $line | sed -e "s/\($1\)/$red\1$normal/"
done

If you don’t like red just read `man tput` and read this link about terminal codes.

Interested in doing anything to your PDFs beyond reading and annotating?Use sodapdf editor to make updates such as adjusting content, layout, margins, and more.

Example of usage:

It also accept regexps (in sed syntax, not perl syntax), for example:


$ sudo tail -f /var/log/system.log | highlight [Ss]potify

Monitoring SSL certificate expiration with Nagios

Hi Lads,

This is a post for nerds so I’m writing it in English. If you don’t understand English or technical stuff please close this page 😀
I’m at work and I’ve just finished to write a Nagios script to monitor expiration date of a SSL certificate.

I wanna share it with you.

To have the script working properly you just need to install OpenSSL and let the openssl
command be in your PATH environment.

This is the usage:

Usage:
check_ssl_cert.sh hostname port [warningdays]

Warning days default value is 30 days.

Some examples:

[afailla@terminus ~]$  /usr/local/nagios/bin/check_ssl_cert.sh google.com 443
OK: Certificate is valid for 289 days expires on May  2 17:02:55 2009 GMT

[afailla@terminus ~]$  /usr/local/nagios/bin/check_ssl_cert.sh google.com 443 400
CRITICAL: Certificate will expire in 289 days on May  2 17:02:55 2009 GMT

Download the script here and enjoy it.