LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 05:22 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

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

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 05:31 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466
Blog Entries: 6

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

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

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 08:22 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

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


Reply



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 05:16 PM
Some of the output redirected to /dev/null appears on the screen while 'scripting' gregorian Linux - Newbie 27 06-23-2008 09:44 AM
I've got a message about "/dev/null: access denied" Saulo SUSE / openSUSE 2 04-14-2006 10:37 AM
reoccuring /dev/null error on bootup mehesque Linux - Newbie 3 01-13-2004 04:48 PM
All output to /dev/null? Satriani Programming 13 10-17-2003 01:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:33 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
Open Source Consulting | Domain Registration