Skip site navigation (1)Skip section navigation (2)
Date:      14 Feb 2001 07:34:25 -0600
From:      Tim Ayers <tayers@bridge.com>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: redirecting output
Message-ID:  <k86t8k2m.fsf@tim.bridge.com>
In-Reply-To: Peter Brezny's message of "Tue, 13 Feb 2001 15:31:21 -0500 (EST)"
References:  <Pine.BSF.4.05.10102131530370.10075-100000@black.purplecat.net>

next in thread | previous in thread | raw e-mail | index | archive | help
>>>>> "P" == Peter Brezny <peter@black.purplecat.net> writes:
P> I'm trying to redirect output from a process  when i use this

P> virtual2# nice ( /usr/bin/tar cvflj - /usr/local/scripts >
P> /bkup/archive/`date +%y%m%d`-test.bz
P> 2 ) 2 > & 1 > /bkup/archive/test.log

P> It tells me i've got an ambiguous output redirect...

It looks like you are tar'ing up an archive and want to capture the
output from the command to a log file, right? And the "2 > & 1"
implies an sh variant, right?

Try this

  nice /usr/bin/tar cvflj /bkup/archive/`date +%y%m%d`-test.bz \
    > /bkup/archive/test.log 2>&1

You don't need to send tar to stdout and then capture it. 
"tar cf - * > foo.tar" should be completely equivalent to
"tar cf foo.tar *" without the complication of another redirect. It
also removes the need for the subshell which isn't helping anything.

Also note when you are redirecting stderr to stdout (2>&1) _and_
redirecting stdout somewhere, you need to do them in the opposite
order of intuition. That is because the 2>&1 works by cloning stdout
and attaching it to stderr. If you do 2>&1 first, it clones stdout,
which is the console, so you end up right where you started. But if
you do the "> myfile.txt" first, then 2>&1 clones the "> myfile.txt"
redirection and everything works hunky dory.

HTH and
Hope you have a very nice day, :-)
Tim Ayers (tayers@bridge.com)





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?k86t8k2m.fsf>