|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
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 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Dear bakunin, Thanks for the explanation, this works fine for me: Code:
ntpdate pool.ntp.org >> $TMP 2>&1 Regards ![]() -- Santi Saez |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| redirect stdout and stderr to file wrong order problem with subshell | Osim | Shell Programming and Scripting | 3 | 04-14-2011 11:49 AM |
| Redirect STDOUT and STDERR of chsh | austinharris43 | Red Hat | 1 | 03-22-2011 02:58 AM |
| Redirect stdout/stderr to a file globally | islegmar | Shell Programming and Scripting | 2 | 04-22-2009 10:23 AM |
| How to redirect stderr and stdout to a file | sushantnirwan | Shell Programming and Scripting | 8 | 08-28-2008 09:23 AM |
| Redirect stdout and stderr | zcurtis | Shell Programming and Scripting | 8 | 09-02-2002 06:13 AM |
|
|