Color Underline and Bold letter in shell script

Hi All,
This is my first port.....

I am using AIX 5L, installed 10g database.
On daily basis we takes rman backup.
This backup status info strored in a log file.

I write a script to know the status of back means I will fire this script and this script will send a mail to me.

#!/bin/bash
ADMIN="xxxx@aaaaa.com"
. $HOME/.profile
SID=PROD
for SID in PROD
do
  cd /rman_bkp/logs
#
  cp /rman_bkp/logs/level0_backup_DB*.log /rman_bkp/logs/dbbkp.lst
  grep RMAN- /rman_bkp/logs/dbbkp.lst > /rman_bkp/logs/dbbkp_err.lst
  if [ `cat /rman_bkp/logs/dbbkp_err.lst|wc -l` -gt 0 ]
  then
    echo "DB bkp gone in ERROR :\n" > rman_bkp_st.lst
    cat /rman_bkp/logs/dbbkp_err.lst >> rman_bkp_st.lst
  else
    echo "All DB bkp Completed Successfully" >> rman_bkp_st.lst
  fi
  cat rman_bkp_st.lst|mailx -s "${SID} RMAN BACKUP STATUS" $ADMIN
done

now the question is :

can I make this echo part of script in BOLD, UNDERLINE and give some color to this ?????

so that when this script run and send me a mail the echo part will look like heading.

Please suggest
Any help appriciate

Thanks in ADV

Terminals.. in the Unix sense... have capabilities. Even pseudo-terminal graphical clients.

The "right" answer is to properly query the terminal capabilities and use the data passed back as the "right" way to present terminal attributes.

For example.... doing bold=`tput bold` (or you use $()'s for ksh or bash) will get you the capabilities string for enabling BOLD on the terminal.

sgr=`tput sgr0` will give you the string for doing a capabilities reset.

So.. then, you can:

echo "The following is ${bold}BOLD${sgr}... see it?"

To get underline, smul=`tput smul`

Now... color is HARDER. Unless you limit your terminal choices. You can look at your terminal capabilities in total using "infocmp".. HOWEVER, that assumes you have a terminal definition that adequately covers your whole set of terminal capabilities (and... having done this for a LONG time... most DO NOT cover the whole set).

On ANSI like terminals, you can usually do tput setaf <number> to set a foreground color and tput setab <number> to set a background color... Setting the palette of colors is again a VERY terminal - to - terminal specific thing... sometimes it can be altered, sometimes not. Some terminals allow selection of colors using a longer syntax wherein color values can be given. Again, color is a "less" portable option.

The termcap and (now) terminfo way of handling terminal capabilities is a VERY good and generic way of dealing with multi-vendor devices. As with most all things Unix, the "standard" is to support them all!!!!

As I wrote in Chapter 14 of my book, Pro Bash Programming:

"Traditionally, screen manipulation is done through the termcap or terminfo database that supplies the information necessary to manipulate any of dozens or even hundreds of types of terminal. The shell interface to the database is an external command, tput.

On some systems, tput uses the termcap database; on others (mostly newer systems) it uses the terminfo database. The commands for the two databases are not the same, so a tput command written for one system may not work on another.

On one system, the command to place the cursor at the 20th column on the 10th row is:

tput cup 9 19

On another system, the command is:

tput cm 19 9

These commands will produce the correct output for whatever type of terminal is specified in the TERM variable. (Note: tput starts counting at 0.)

However, the plethora of terminal types has, for all intents and purposes, been reduced to a single, standard type. This standard, ISO 6429 (also known as ECMA-48, and formerly known as ANSI X3.64 or VT100), is ubiquitous, and terminals that do not support it are few and far between. As a result, it is now feasible to code for a single terminal type. One advantage of this homogeneity is that the necessary coding can be done entirely within the shell. There's no need for an external command."

The following codes gives you what you need:

## bold
printf '\e[1m'

## red foreground
printf '\e[31m'

## red background
printf '\e[41m'

## underline
printf '\e[4m'

## colours
  black=0
    red=1
  green=2
 yellow=3
   blue=4
magenta=5
   cyan=6
  white=7

Hi experts,

Thanks for the prompt reply.

I am not very much experts with sripting.

Please let me know how can I use your provided code number within my script. say for example:
If I need this part of the script bold with underline:

echo "All DB bkp Completed Successfully" >> rman_bkp_st.lst

Then how can I do this, plz help me to cutomise the code.

Also plz let me know if I use tput in the script... will this effect whole OS setting or the changes will be use by this script only.....

Thanks again.

printf "\e[1;4m%s\e[0m\n" "All DB bkp Completed Successfully" >> rman_bkp_st.lst

Hi,
Thanks for the prompt reply again !
I tried as per suggest but getting this output on both OS level file (rman_bkp_st.lst) and my outlook mail.

(As I mention earlier this script generate a file rman_bkp_st.lst on OS and then send me the mail to my mail box)

\e[1;4mAll DB bkp Completed Successfully\e[0m

Please suggest what Im missing.
Thanks again !

Those codes are for a terminal, not a mail client.

Try replacing...

  if [ `cat /rman_bkp/logs/dbbkp_err.lst|wc -l` -gt 0 ]
  then
    echo "DB bkp gone in ERROR :\n" > rman_bkp_st.lst
    cat /rman_bkp/logs/dbbkp_err.lst >> rman_bkp_st.lst
  else
    echo "All DB bkp Completed Successfully" >> rman_bkp_st.lst
  fi
  cat rman_bkp_st.lst|mailx -s "${SID} RMAN BACKUP STATUS" $ADMIN

...with...

  if [ `wc -l < /rman_bkp/logs/dbbkp_err.lst` -gt 0 ]
  then
    echo "<B>DB bkp gone in ERROR :</B><BR><PRE>" 
    cat /rman_bkp/logs/dbbkp_err.lst
    echo "</PRE>"
  else
    echo "<B>All DB bkp Completed Successfully</B><BR>" 
  fi > rman_bkp_st.html
  (
    echo "Subject: ${SID} RMAN BACKUP STATUS"
    echo "MIME-Version: 1.0"
    echo "Content-Type: text/html"
    echo "Content-Disposition: inline"
    cat rman_bkp_st.html
  ) | /usr/sbin/sendmail $ADMIN

Hi Ygor,

Thanks for the prompted help.... it works :b:
and giving the expected output in my mailbox through script.

Just one more thing, if I can fill some color + underline the echo part of the script ?????

Please suggest !

Thanks again

You can use any html tags you like.

Hi Ygor,

All set proper.. Thanks for all your help budy..... :b:

ygor...need to know one more thing..

can I BLINK a part of echo statement.....
I tried this one....

echo "<BLINK><font size="2" face="Verdana" color=green>All DB bkp Completed Successfully.</font></BLINK><BR><BR>"

but it doen'nt work...

Is there any way to do so ????

Thanks again

Hi all,

I wrote a script which run in my AIX box, store a copy of output in to the same box and then send this copy to my mail address into windows outlook.... it is working as exected and sending me mail.....

I just want to add some blinking text....
eg:

if [condition}
ehco " This is good"
else
echo "Attention: this is not good "
fi

Please suggest is there any way to blink this else part of the script.
so that when it send me a mail (into outlook) it shows in blinking.....

Please suggest !

You might have trouble with Blink

For images use <IMG> e.g... <img src="http://i1236.photobucket.com/albums/ff442/starfruit2/0099.gif" border="0">

Thanks for the update !

so I am using code like this... plz varify

if [ `wc -l < /d05_proddbx/dba/My_scr/dbbkp_err.lst` -gt 0 ]
then
echo "<font size="2" face="Verdana" color=red>DB BKP gone in ERROR :<BR></font><PRE>"
cat /d05_proddbx/dba/My_scr/dbbkp_err.lst
echo "</PRE>"
else
echo "<font size="2" face="Verdana" color=green>All DB bkp Completed Successfully.</font><BR><BR>"
<img src="http://i1236.photobucket.com/albums/ff442/starfruit2/0099.gif" border="0">
fi >> rman_bkp_st.html

IMG is a html tag that you want in your file, so use echo...

echo '<img src="http://i1236.photobucket.com/albums/ff442/starfruit2/0099.gif" border="0"> '

Hi,

Do as per your suggestion, but the mail is send to my "Junk E-Mail" to my outlook and also the output is not as exected.
The output is like:

<http://i1236.photobucket.com/albums/ff442/starfruit2/0099.gif> All DB bkp Completed Successfully.

please suggest where I am making mistake.
Thanks

Hi Ygor,

Waiting for your prompted reply....

Thanks