The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Redirecting STDERR message to STDOUT & file at same time vikashtulsiyan Shell Programming and Scripting 10 04-09-2008 03:34 PM
how can i redirect stderr to file in Make? umen Shell Programming and Scripting 0 02-15-2007 04:04 AM
redirect stderr and/or stdout to /dev/null from command line knc9233 UNIX for Dummies Questions & Answers 1 01-25-2007 12:24 PM
stderr & stdout to a file and the right exit code up69 Shell Programming and Scripting 2 08-17-2006 02:40 PM
Redirect stdout and stderr zcurtis Shell Programming and Scripting 8 09-02-2002 07:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-02-2006
Santi Santi is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 23
Redirect stdout & stderr and append to a file

Hello

I want to append to a file the stdout and stderr outputs from script, this works fine:

Code:
$ ./script.pl >> /tmp/outputs.txt 2>> /tmp/outputs.txt
But I want to use only one redirection "command", but it fails:

Code:
$ ./script.pl &>> /tmp/outputs.txt  
-bash: syntax error near unexpected token `>'
This works using "create redirection" (>) instead of "append redirect" (>>):

Code:
$ ./script.pl &> /tmp/outputs.txt
It's possible to redirect and *append* to a file only with one redirection?

Thanks!

--
Santi Saez
  #2 (permalink)  
Old 01-02-2006
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
Why you "want to use just one redirection" eludes me.

It is possible to redirect one output channel to another like "2>&1" which means "put the output of channel 2 (stderr) where right now channel 1 (stdout) goes" and let channel 1 point to a file:

process >>file 2>&1

But to be honest i would prefer you first solution with separately mentioned files for stdout and stderr anytime on weekdays and twice on sundays - it makes a much easier to maintain code AND it is not position dependent:

process >file 2>&1

will have stderr and stdout go to <file>, but:

process 2>&1 >file

will have stdout go to <file> and stderr to - screen! , because when the direction channel 2 should point to is evaluated channel 1 is still pointing to the terminal and not to the file.

This is one of the most common errors in crontabs and responsible for an awful lot of unnecessary (and unwanted) mails to root (the cronjobs replacement for a terminal).

bakunin
  #3 (permalink)  
Old 01-02-2006
Santi Santi is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 23
Dear bakunin,

Thanks for the explanation, this works fine for me:

Code:
ntpdate pool.ntp.org >> $TMP 2>&1
Regards

--
Santi Saez
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 09:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0