LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-17-2006, 12:09 PM   #1
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Rep: Reputation: 0
Any way to split up STDOUT and STDERR, and then recombine in the right order?


OK, the question may be a bit misleading, so here is what I am trying to do:

I have a bunch of jobs in cron, and I would like all the output to eventually end up in a log file in exactly the order it would come out if run interactively.

However, I would like to somehow mark the lines that come out via STDERR so that I can say color them or something so I can pick them out more easily. This may be as simple as prepending some predetermined series of characters to all STDERR lines like @@@@@ or such.

Is this possible?

Thanks
 
Old 04-17-2006, 12:30 PM   #2
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 417

Rep: Reputation: 53
I suppose you could pipe the STDERR (or STDOUT) output through sed, then push that into a file:

$ binary1 1> log.txt 2>&1 |(sed "s/^/STDERR:/" >> log.txt)

(I *think* this would work. I haven't tested it, and I really don't know if it will work properly. Give it a shot and see what happens, I guess...)
 
Old 04-17-2006, 01:02 PM   #3
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
Hmm, doesn't seem to work. Perhaps with parentheses around the first part, thus:

(binary1 1> log.txt)

note the 1 before the > is superfluous in my limited experience.
 
Old 04-17-2006, 02:00 PM   #4
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
not working yet, further suggestions welcomed.
 
Old 04-17-2006, 02:25 PM   #5
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
OK, so

(find /lcl/fst/ -name "*ooo*" 1> log.txt) 2>&1 |(sed "s/^/STDERR:/" >> log.txt)


Does separate out STDERR and STDOUT, but it doesn't reassemble them in the right order; the STDERR: lines are all at the bottom of the file. I'd like all the lines to be in the same order as emitted.
 
Old 04-17-2006, 02:57 PM   #6
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
(find /lcl/fst/ -name "*ooo*" >> log.txt) 2>&1 |(sed "s/^/STDERR:/" >> log.txt)

assembles the line in CLOSER to the expected order but still not quite.
 
Old 04-17-2006, 03:25 PM   #7
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
Sounds like I need to somehow "un-buffer" stderr. By googling I see this is possible in Perl. Is it possible in a shell?
 
Old 04-17-2006, 03:57 PM   #8
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
getting closer:

((find /lcl/fst/ -name "*ooo*") 3>&1 1>&2 2>&3 ) | sed 's/^/STDERR:/'

gives me what I want to the console; now to redirect the whole shebang into a file!
 
Old 04-17-2006, 03:59 PM   #9
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
Nope, still the wrong order, but at least lines aren't getting interrupted.
 
Old 04-17-2006, 04:08 PM   #10
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
OK, there HAS to be a way to do this, because I got the idea from emacs. In our implementation here, when you issue a command, stdout and stderr both go to the console, but stdout is the default font color, and the stderr stuff is another color. I just want to replicate this for an HTML page to view cron job status.

Last edited by Lumberg; 04-17-2006 at 04:31 PM.
 
Old 04-18-2006, 08:38 AM   #11
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
Anybody else with an idea?
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
TCSH: redirect stdout and stderr seperately ugenn Linux - General 3 02-07-2016 03:23 PM
how does one use DD to recombine files from using pipe to split files originally? nerdful1 Linux - General 3 03-28-2006 07:46 AM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 07:55 AM
Reopen the stdout and stderr rahul_kulkarni Programming 3 02-21-2005 06:55 AM
shell short question(stdout, stderr) blackzone Programming 4 11-11-2004 09:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:38 AM.

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