LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-17-2006, 02:56 PM   #16
Lumberg
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Rep: Reputation: 0

Wow, what a thorny problem.

I got as far as

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

but there is some sort of race condition with the writing of STDERR and STDOUT which still will jumble the lines.

grrrrrr
 
Old 04-18-2006, 03:07 AM   #17
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OEL
Posts: 9,158

Rep: Reputation: 238Reputation: 238Reputation: 238
Hey, reviving a 6 month old thread !

You can run the "script" command before running your find, and exit when it's done.

That way you'll have an ordered log of stdout and stdin in the typescript file.
 
Old 05-21-2008, 04:30 AM   #18
Igorts
LQ Newbie
 
Registered: May 2008
Location: Israel
Posts: 1

Rep: Reputation: 0
Thumbs up Final solution

This thread is very old, yet I wanted to post the solution in case someone reads this:

Lets say you want to run "some_command", log its outputs (including stderr) and also output stderr to the screen:

Code:
((some_command 2>&1 1>&3 | tee /dev/stderr) 3>&1) > logfile
This is not perfect because it does not return a correct exit code (it always returns 0 - the exit code of 'tee').
So we improve this a little bit:

Code:
((some_command 2>&1 1>&3 | tee /dev/stderr ; exit ${PIPESTATUS[0]}) 3>&1) > logfile
In case "some_command" is stored in a variable such as $cmd, I would suggest adding "eval" so that quotes are handled correctly:

Code:
((eval $cmd 2>&1 1>&3 | tee /dev/stderr ; exit ${PIPESTATUS[0]}) 3>&1) > logfile

Last edited by Igorts; 05-22-2008 at 04:44 AM.
 
Old 05-22-2008, 12:47 PM   #19
stefanlasiewski
Member
 
Registered: Aug 2003
Location: Berkeley, California, USA
Distribution: Red Hat Enterprise Linux, Debian & Ubuntu
Posts: 92

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Igorts View Post
This is not perfect because it does not return a correct exit code (it always returns 0 - the exit code of 'tee').
So we improve this a little bit:

Code:
((some_command 2>&1 1>&3 | tee /dev/stderr ; exit ${PIPESTATUS[0]}) 3>&1) > logfile
Good solid example of Bash IO Redirection. Thanks!

Last edited by stefanlasiewski; 05-22-2008 at 12:55 PM.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing shell script with mail < logfile humbletech99 Programming 2 11-22-2005 08:20 AM
io redirection doesn't work? 2>&1 >> logfile.log Thinking Linux - General 5 06-10-2005 04:31 AM
ntfs logfile error on slack10.0 2.6.9 eitch Slackware 3 11-22-2004 01:23 PM
Can I redirect script output to a file without ">> $LOGFILE" at the end of each line davee Linux - General 1 12-19-2003 05:01 AM
fatal server error: cannot move logfile XFree86.0.old Scruff Linux - Software 3 11-02-2003 01:00 PM


All times are GMT -5. The time now is 10:55 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration