Color Underline and Bold letter in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Color Underline and Bold letter in shell script
# 1  
Old 02-11-2011
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.
Code:
#!/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

Last edited by Scott; 02-11-2011 at 02:35 AM.. Reason: Please use code tags
# 2  
Old 02-11-2011
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!!!!
# 3  
Old 02-11-2011
Quote:
Originally Posted by mcagaurav
can I make this echo part of script in BOLD, UNDERLINE and give some color to this ?????

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:
Code:
tput cup 9 19

On another system, the command is:
Code:
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:
Code:
## 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

# 4  
Old 02-15-2011
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:
Code:
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.

Last edited by Yogesh Sawant; 02-15-2011 at 07:06 AM.. Reason: added code tags
# 5  
Old 02-15-2011
Code:
printf "\e[1;4m%s\e[0m\n" "All DB bkp Completed Successfully" >> rman_bkp_st.lst

# 6  
Old 02-15-2011
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 !
# 7  
Old 02-15-2011
Those codes are for a terminal, not a mail client.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Bold letter in email body

Hi All, The below is the email text and i want few words in BOLD. I am writing the below message in to a .txt file and calling it in a function which generated email. when i run at cmd prompt it is working fine , but wehn i run a script .sh it is not working. Below is the text printing in to... (2 Replies)
Discussion started by: kiranparsha
2 Replies

2. Shell Programming and Scripting

Bold 1 word in a shell script

I want to bold one word in shell script. I want the value for num bold when it is inputted. My code does not bold the value. It's like its not even there. echo -n "Please read a number" read num ; echo "${bold} $num ${offbold}" Thank you, Ccccc (6 Replies)
Discussion started by: Ccccc
6 Replies

3. Shell Programming and Scripting

Sending email message in colour and bold letter

The code echo -e "\033[34m Test \033[0m Mail" when i execute this command line i get proper output but when i mail the output of this command through sendmail it doesn't appear. Basically I want to send email message in diffrent colours, bold letter using shell script. (2 Replies)
Discussion started by: baps
2 Replies

4. Shell Programming and Scripting

Bold and Underline - not displyed in more/less/vi

I have a script main.shl which has few lines like this #bold tput smso echo "\t\tsome statement\t\t" tput rmso I am executing the main.shl from the shell and redirected its output to a separate file like this $main.shl >main.log 2>&1 & once after running this script, if I "cat" the... (0 Replies)
Discussion started by: ramkrix
0 Replies

5. Shell Programming and Scripting

Bold characters in a file using Shell script

Hi, When I am running below mentioned script then the characters become bold but after opening the same file in Windows, Instead of getting bold characters i am getting some garbage value for \033Kunal Dixit Output in Windows (after ftp the file): but in windows , i am getting My name is... (0 Replies)
Discussion started by: kunal_dixit
0 Replies

6. Shell Programming and Scripting

color,bold

hi friend , I am generating a csv file i,e output file E104|0|06/04/1994|The values E005 and E001 are not equal. E106|0|01/09/1993|The values E001 and E002 are not equal. E106|0|01/09/1993|The values E003 and E002 are not equal. E108|0|02/30/1995|The values R001 and E001 are not equal.... (0 Replies)
Discussion started by: charandevu
0 Replies

7. Shell Programming and Scripting

ksh - how to echo something in color and bold

Hi all, I was to echo Hi in Red and Bold ; and echo There is in Green and bold I got bold to working using tput bold but i am having hard time getting the color. Any help is appreciated, jak (4 Replies)
Discussion started by: jakSun8
4 Replies

8. Shell Programming and Scripting

Specifying font type and color in a shell script

Hi, I am new to shell script. Can you please tell me, whether can we specify font type and color in a shell script? If so, how to do this? Thanks in advance. (4 Replies)
Discussion started by: Vani_Govind
4 Replies

9. UNIX for Dummies Questions & Answers

How to underline/bold and how to align output

Hi, I work with AIX 5 and have two basic questions: 1) How do I underline/bold a word in a text output? Any way to do it with echo command? basic example: echo "FOLDER " >> folder.txt ( I wish the word FOLDER to be underlined and bold). 2) Suppose I have the following pipe delimited... (1 Reply)
Discussion started by: clara
1 Replies
Login or Register to Ask a Question

Featured Tech Videos