LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-13-2009, 06:22 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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
 
Old 05-13-2009, 06:25 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Usually redirecting both the standard output and the standard error to /dev/null is enough:
Code:
/path/to/script > /dev/null 2>&1
 
Old 05-13-2009, 06:31 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Rep: Reputation: 51
what does 2>&1 represent?
 
Old 05-13-2009, 06:36 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
http://lists.freebsd.org/pipermail/f...ay/123250.html
 
Old 05-13-2009, 06:45 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by your_shadow03 View Post
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.
 
Old 05-13-2009, 09:22 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting a desktop-oriented program's mandatory X output to /dev/null for a server srunni Linux - Server 3 07-16-2008 06:16 PM
Some of the output redirected to /dev/null appears on the screen while 'scripting' gregorian Linux - Newbie 27 06-23-2008 10:44 AM
I've got a message about "/dev/null: access denied" Saulo SUSE / openSUSE 2 04-14-2006 11:37 AM
reoccuring /dev/null error on bootup mehesque Linux - Newbie 3 01-13-2004 05:48 PM
All output to /dev/null? Satriani Programming 13 10-17-2003 02:31 PM


All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration