Operating System - HP-UX
1834208 Members
2312 Online
110066 Solutions
New Discussion

Re: Redirect a message or log to console

 
SOLVED
Go to solution
Manuales
Super Advisor

Redirect a message or log to console

hi... how can i redirect the log or a message to console, it is to say, when i have a problem i want see messages on console since site (obiously, i have scripts on cron but i want redirect errors or output to console?
how do i do it?

is like:
echo "hi" > /dev/console ??


Thanks, Manuales
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Redirect a message or log to console

echo "hi" > /dev/console will work but your should note that most error messages do not use stdout but rather stderr so when you start your script you should really do something like this:

myscript > /dev/console 2>&1

If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: Redirect a message or log to console

You are correct Sir.

Try it. It won't hurt anything.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Manuales
Super Advisor

Re: Redirect a message or log to console

Hi .. thanks !!!

with this line:
myscript > /dev/console 2>&1

i can't understand: 2>&1

thanks, Manuales
James R. Ferguson
Acclaimed Contributor

Re: Redirect a message or log to console

Hi Manuales:

# myscript > /dev/console 2>&1

...says to redirect the standard output (STDOUT or file descriptor #1) of 'myscript' to /dev/console. Then, to that, duplicate the output of standard error (STDERR or file descriptor #2) to whatever STDOUT points.

See the manpages for 'sh-posix' in the section titled "Input/Output" for more information.

Regards!

...JRF...
Manuales
Super Advisor

Re: Redirect a message or log to console

then ... with next line:
myscript > /dev/console 2>&1

i can see all messages of script executed in /dev/console as much messages as errors?

thanks, Manuales.

James R. Ferguson
Acclaimed Contributor

Re: Redirect a message or log to console

Hi Manuales:

Yes. As Clay noted, good software writes error and warning messages to STDERR and its other output to STDOUT. The redirection shown pushes *both* those streams to the same place --- the console in this case.

Regards!

...JRF...
Raj D.
Honored Contributor

Re: Redirect a message or log to console

Hi Manuales ,

Its redirecting , stdout and stderr together with ">&"

2>&1 is :

2 for standard error. stderr.
1 for standard output. stdout.

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "