Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Display Console errors in Red color Post 302550407 by Corona688 on Thursday 25th of August 2011 04:54:30 PM
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.
 

6 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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
fifo(3tcl)																fifo(3tcl)

NAME
fifo - Create and manipulate u-turn fifo channels SYNOPSIS
package require Tcl package require memchan fifo DESCRIPTION
fifo creates a stream-oriented in-memory channel and returns its handle. There is no restriction on the ultimate size of the channel, it will always grow as much as is necessary to accommodate the data written into it. In contrast to the channels generated by memchan a channel created here effectively represents an U-turn. All data written into it can be read out, but only in the same order. This also means that a fifo channel is not seekable. The channels created here can be transferred between interpreters in the same thread and between threads, but only as a whole. It is not possible to use them to create a bi- or unidirectional connection between two interpreters. Memory channels created by fifo provide two read-only options which can be queried via the standard fconfigure command. These are -length The value of this option is the number of bytes currently stored in the queried memory channel. -allocated The value of this option is the number of bytes currently allocated by the queried memory channel. This number is at least as big as the value of -length. As the channels generated by fifo grow as necessary they are always writable. This means that a writable fileevent-handler will fire con- tinuously. The channels are also readable if they contain more than zero bytes. Under this conditions a readable fileevent-handler will fire continu- ously. NOTES
One possible application of memory channels created by memchan or fifo is as temporary storage device to collect data coming in over a pipe or a socket. If part of the processing of the incoming data is to read and process header bytes or similar fifo are easier to use as they do not require seeking back and forth to switch between the assimilation of headers at the beginning and writing new data at the end. SEE ALSO
fifo2, memchan, null KEYWORDS
channel, fifo, i/o, in-memory channel, memchan, stream COPYRIGHT
Copyright (c) 1996-2003 Andreas Kupries <andreas_kupries@users.sourceforge.net> Memory channels 2.1 fifo(3tcl)
All times are GMT -4. The time now is 09:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy