LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 12-23-2008, 12:42 PM   #1
pileofrogs
LQ Newbie
 
Registered: Mar 2007
Location: Seattle
Distribution: CentOS, Fedora, Ubuntu
Posts: 17

Rep: Reputation: 0
Question How to copy output to multiple fd?


I want to make both stderr and stdout go to syslog while stderr also goes to the screen. I'm running a cron job and I've redirected stdout to logger and I leave stderr to go to cron and hence email to me. What I want is for the stderr messages to also go to logger and syslog. That probably made no sense, so here's the example crontab

Quote:
MAILTO=me@example.com

0 0 * * * whizbang | logger -t 'whizbang'
As you can see, stdout will go to syslog and stderr will go in an email to me@example.com

I've figured out that something like :

Quote:
exec 3>&1; whizbang 2>&1 >&3 | tee -a /dev/fd/3 >&2 ; exec 3>&-
will work.. sortof. Unfortunately, the stderr winds up all bunched at the end instead of interleaved with the stdout. For example, if whizbang contained:

Quote:
echo "foo"
echo "bar" >&2
echo "baz"
I'd get an email saying "bar" and syslog would say "foo" "baz "bar", not "foo" "bar" "baz", which makes it harder to figure out what caused the error.

So, my question is: does anyone know how to produce a stderr on one file descriptor and a combined stderr+stdout on another file descriptor without losing the order of the output?

Thanks!
-Dylan
 
Old 12-23-2008, 03:58 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
The problem is that stdout is buffered and stderr isn't. perl allows you to set autoflush, so you might be better off looking at implementing it that way.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to copy output to HERE royeo Linux - Newbie 3 07-07-2006 03:10 AM
trying to copy the output of /sbin/lspci to another window interndan Slackware 9 11-18-2005 04:24 AM
Copy from DVD - Input/Output error nifflerX Linux - General 2 10-12-2005 02:32 PM
Copy output of Terminal Buffer tryangle Debian 2 08-08-2005 04:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:24 PM.

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