LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 12-27-2002, 03:55 PM   #1
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: Debian Red-Hat Ubuntuu Solaris CentOS
Posts: 78

Rep: Reputation: 15
Command Shell Paramters


Hi Everyone!

This is an easy one for those with long time scripting in BASH or any of the other shells.

I know that the ">" redirects output to the next parameter but what about in a case like this? This is in a CRON job BTW

php cmd.php > /dev/null 2>&1

So far I understand that php runs cmd.php and then any resulting output is sent to /dev/null (ie. go bye bye) but what's the last set of args for?

I suppose that this is to keep the user account running this scron job from getting bombarded with cron run results but could there be more?
 
Old 12-27-2002, 04:39 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
There are two output streams from a program:

stdout (filedescriptor 1, normal output)
stderr (filedescriptor 2, error mesages output)

and one input stream: stdin (filedescriptor 0)

$php cmd.php >/dev/null
would make all normal output disappear, but errormessages are still output.

stdout i on filedescriptor 1, so you could use 1>/dev/null as well.

$php cmd.php 2>/dev/null
would make all errormessages disappear, but all normal output would still be there.

$php cmd.php > /dev/null 2>&1
will output nothing at all: first stdout (which is on filedescriptor 1) is redirected to a file (/dev/null in this case to make ik disappear).
Then filedescriptor 2 (stderr, error messages) is redirected to the same place as stdin (1).

So, in brief:
"2>&1" means more or less: "Make error messages go where the normal output is going"

Note you cannot change the order: "2>&1 > /dev/null" will not work the same way. You can however make normal output go to one_file and error messages to another_file:

$php cmd.php >one_file.txt 2>another_file.txt

Here the order is not important, only in the special case of "2>&1".
 
Old 12-28-2002, 04:09 PM   #3
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: Debian Red-Hat Ubuntuu Solaris CentOS
Posts: 78

Original Poster
Rep: Reputation: 15
Fantastic.

I knew there'd be someone who could regurgitate that easily! Thanks!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH - passing paramters to programs dkrysak Programming 1 11-18-2005 03:16 PM
Check ./configure paramters? jon3k Linux - Software 3 03-01-2005 11:53 AM
what is the shell command to.... praefex Linux - Newbie 2 08-18-2003 05:25 PM
shell command i_is_cat Linux - General 1 08-13-2003 03:09 AM
QT --how to do a shell command linuxlah Programming 2 08-22-2002 02:27 PM


All times are GMT -5. The time now is 10:58 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration