LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Output error / message to /dev/null (https://www.linuxquestions.org/questions/linux-newbie-8/output-error-message-to-dev-null-725655/)

ust 05-13-2009 05:22 AM

Output error / message to /dev/null
 
I have a batch job that run many commands , sometimes it generate errors ( for different reasons ) , so that there are many messages pop to the console , and write to messages log , can advise if I want the batch job DO NOT output anything or just output to /dev/null ( because there are too many messages ) , what can i do ? thx

colucix 05-13-2009 05:25 AM

Usually redirecting both the standard output and the standard error to /dev/null is enough:
Code:

/path/to/script > /dev/null 2>&1

your_shadow03 05-13-2009 05:31 AM

what does 2>&1 represent?

repo 05-13-2009 05:36 AM

http://lists.freebsd.org/pipermail/f...ay/123250.html

colucix 05-13-2009 05:45 AM

Quote:

Originally Posted by your_shadow03 (Post 3539216)
what does 2>&1 represent?

From Chapter 19 of the advanced bash scripting guide:
Code:

2>&1
      # Redirects stderr to stdout.
      # Error messages get sent to same place as standard output.
        >>filename 2>&1
            bad_command >>filename 2>&1
            # Appends both stdout and stderr to the file "filename" ...
        2>&1 | [command(s)]
            bad_command 2>&1 | awk '{print $5}'  # found
            #  Sends stderr through a pipe.
            #  |& was added to Bash 4 as an abbreviation for 2>&
            #+ but as of version 4.0 this still does not work.


chrism01 05-13-2009 08:22 PM

Note that if you are getting msgs (particularly on stderr) you should redirect to a logfile so you can fix the issues...


All times are GMT -5. The time now is 07:10 PM.