1753701 Members
4925 Online
108799 Solutions
New Discussion юеВ

Redirect out put to ?

 
SOLVED
Go to solution
P-Dicky
Frequent Advisor

Redirect out put to ?

Good Morning,

Just a dozen or so more questions!

How would I redirect this out put to null?

# ./demo_finish_recovery.sh
mv: /fpc/archivelog: rename: Device busy
mv: /fpc/data: rename: Device busy
7 REPLIES 7
Coolmar
Esteemed Contributor
Solution

Re: Redirect out put to ?

Hi,

# ./demo_finish_recovery.sh >/dev/null 2>&1
Ivan Krastev
Honored Contributor

Re: Redirect out put to ?

Thi will redirect all to null:

> /dev/null


This only errors :
2> /dev/null




regards,
ivan


Bill Hassell
Honored Contributor

Re: Redirect out put to ?

Text from a script can be issued to two different devices, stdout and stderr. For an interactive run (ie, started from a terminal), stdout and stderr both go to the screen. Normally, error messages such as the "Device busy" mentioned above are sent to stderr and can be suppressed by redirecting stderr to /dev/null.

The std files all have the same numbering convention: 1=stdin 2=stdout 3=stderr, so to get rid of just the error messages, use 2>/dev/null where 2=stderr, > menas to redirect and /dev/null is the bit-bucket. If you want normal as well as error messages to be redirected, you can do it two ways:

./demo_finish_recovery.sh 1>/dev/null 2>/dev/null
./demo_finish_recovery.sh 1>/dev/null 2>&1

The first form is straightforward, but the second has a shorthand: 2>&1 which means redirect file #2 into file #1 (which has been already redirected to /dev/null). The redirection must be in the order shown. Note that 1>/dev/null and >/dev/null are equivalent.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: Redirect out put to ?

Hi:

The numbering of the standard file descriptors opened by every standard Unix program are 'stdin' = 0, 'stdout' = 1 and 'stderr' = 2, respectively.

While Bill's examples are correct, he inadvertantly counted from one in associating their names with numbers.

Well-behaved Unix programs use STDERR to report warnings and/or errors leaving STDOUT to the expected output.

When both streams are mixed, STDERR is unbuffered while STDOUT is normally buffered. The presence of a newline character causes the current STDOUT buffer to be flushed. This is useful to remember, particularly in cases where you build output lines from several 'printf' statements with only the last one injecting a newline character.

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: Redirect out put to ?

Thanks James...of course, the standard file numbers are indeed 0 1 2 (I was half-watching Sesame Street on TV at the time...)


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: Redirect out put to ?

The correct solution is to change the demo_finish_recovery.sh script to redirect stderr on only the mv commands. Otherwise you may be missing errors on other commands that are important.

Of course while you are there, you may want to capture the error output and do something if mv fails.
P-Dicky
Frequent Advisor

Re: Redirect out put to ?

Thank you