Display Console errors in Red color


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Display Console errors in Red color
# 1  
Old 07-25-2011
Display Console errors in Red color

I browsed the forums but i couldn't find the best answer.so,i'm posting here again..
I have a parent bash script which calls another child script and the child script is used to deploy the tar file using weblogic deployer.
The script is used to display the output on the console and sent to a log file as well.
My problem is how can i display any error message in the output in a red color on the console?
It would be great if the errors in the log are also shown in red color.The errors could be from the weblogic deployer or from the scripts.

we use this for deploying the war.
HTML Code:
${JAVA_PATH}/java -classpath ${WEBLOGIC_HOME}/server/lib/weblogic.jar weblogic.Deployer 
-adminurl ${WEBLOGIC_ABC_ADMIN_URL} -user ${WEBLOGIC_USERNAME} -password
 $WEBLOGIC_PASSWORD -deploy -targets ${CLUSTER} -name ${RESOURCE_WEB_CONTEXT}
 -upload $WORK_DIR/artifacts/webapp/components/${CONTEXT}-1.0.0-c.war
Appreciate your help in advance.

Thanks
-Ramesh

Last edited by ramse8pc; 07-25-2011 at 05:50 PM.. Reason: wrapped long lines
# 2  
Old 08-25-2011
try this ..
Code:
$ cat filename
#!/bin/bash
pw > script_output 2>err_log
## pw is the not working command to capture o/p in error logfile
## In place of pw, use your command to run
echo -e '\e[0;31m'; cat err_log ; echo -e '\e[0;00m'
$
$ bash filename
j: pw: command not found
$

---------- Post updated at 03:01 PM ---------- Previous update was at 02:57 PM ----------

for more info abt shell colorings ..
Using colors in Shell Script

Last edited by jayan_jay; 08-25-2011 at 06:28 AM.. Reason: code tags
# 3  
Old 08-25-2011
Thanks for the reply.
The solution i'm expecting is when i run the build script all the log statement will be logged to a single log.i don't want a separate log file for errors as that script will be executed by other persons not familiar with it at all.So just wanted to show the Exceptions/errors on the console in red colour as and when they occur while script executes.

Thanks
# 4  
Old 08-25-2011
How is the console supposed to tell the difference, then?
# 5  
Old 08-25-2011
That's the reason if the exceptions/error are shown in red colour on the console then the person executing the script understands that there is something wrong with build and deployment.
one more thing to note is that we output statements to the console as well as to the logs using "tee" command.
eg:
#$JAVA_HOME/java HelloWorldApp 2>&1 | tee -a Hello.log

Hope i conveyed you the pupose.

Thanks
-Ramesh

Last edited by ramse8pc; 08-25-2011 at 04:55 PM.. Reason: point highlighted
# 6  
Old 08-25-2011
Power

I'm not asking why you want them red.

I'm asking how you expect anything to tell the difference between errors and non-errors after you dump the error stream back into stdout with 2>&1. By doing that you lose track of which is which. And since they only appear on the screen after you've done that, it's going to be difficult to separate them again. You really should process them separately.

Trying to build something but it's going to be ugly.

---------- Post updated at 02:54 PM ---------- Previous update was at 02:09 PM ----------

Don't say I didn't warn you.
Code:
#!/bin/sh

trap "rm -f fifo" EXIT

mkfifo fifo

exec 5>logfile

# Run a loop in the background that reads stderr data from fifo,
# prints to terminal and prints to logfile
( while read LINE
  do
        printf "\033[1;31m%s\033[0m\n" "$LINE" >&2
        echo "$LINE"
  done <fifo >&5 ) &

# The first () command is just a substitute for your command
# which prints to stderr and stdout.
# We redirect its stderr into the fifo, where the background
# loop will read it.
( echo asdf >&2 ; echo qwerty ) 2>fifo | while read LINE
do
        # Print to the logfile
        echo "$LINE" >&5
        # print to the screen
        echo "$LINE"
done
# close the logfile
exec 5>&-

rm -f fifo

# wait for the background loop to quit
wait

Also, because of the extra processing loop involved in coloring the red text, the order you get in the file isn't guaranteed to be the same as you get in the terminal.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display file with escaped color codes

Hi, I have a file containing color codes: Fri May 25 17:13:04 2012: Starting MTA: exim4^ Loading cpufreq kernel modules...^How can I display it colorized on a linux terminal? (4 Replies)
Discussion started by: ripat
4 Replies

2. Solaris

X11 errors on Solaris 10 - SL Console not showing up

Hi all, I have been administrating large backup environments for quite some time now, but I have never seen the types of errors I'm getting for a client I have in Asia, so I humbly appeal to your expertise in order to fix things. Set up: StreamLine 8500 library connected to a Solaris... (7 Replies)
Discussion started by: dilibau
7 Replies

3. Shell Programming and Scripting

regarding Color scheme in linux console connected through putty.

Hi All, I am connecting to SunOs 5.8 server from windows machine through putty. My problem is commands are not showing any colours results. I want to see 'ls' command should list directories in 'red' and files in 'green' etc. How to do it . Please help. Also How to enable syntax colouring in... (6 Replies)
Discussion started by: Sooraj_Linux
6 Replies

4. Shell Programming and Scripting

tcsh/csh: set prompt in production to color red

Hi folks This is our prompt at the moment oracle@pinkipinki:/opt/oracle> grep 'set prompt' .cshrc set prompt = "$user@`uname -n`:$cwd> " We wish to have in production the same prompt, but red. Howto do that? I tried a lot a internet manuals, but it doesn't work. (1 Reply)
Discussion started by: slashdotweenie
1 Replies

5. Shell Programming and Scripting

How to have color coded Terminal display,(like linux)

Hi all, I would like to know how to have a color display in the terminal... In the sense that, In many linux terminals,we have color coded for each file type, green for executable ,blue for dirs and so on... I wanted to know how i can have the same arrangement in solaris(b-79a) I am not... (5 Replies)
Discussion started by: wrapster
5 Replies

6. Solaris

Red stop signs in Solaris Management Console 2.1

I've installed Solaris 10 (x86 8/07) on a Dell PowerEdge 2950. When I bring up the Solaris Management Console I get red stop sign looking icons on all areas (System Status, System Configuration, Services, Storage, and Devices and hardware) under This computer. Originally nothing was showing up... (1 Reply)
Discussion started by: kayroreality
1 Replies
Login or Register to Ask a Question