LinuxQuestions.org
Have you heard the LinuxQuestions.org Podcast?
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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
 
Thread Tools
Old 02-03-2004, 03:32 PM   #1
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 143
Thanked: 0
Question How to redirect standard output of piped command to log file


[Log in to get rid of this advertisement]
I have this command in a bash script which record MP3 files in real time:
sox -r 44100 -t ossdsp -w -s /dev/dsp -t raw -c 1 - | lame -s 44.1 -x -b 8 -m m --lowpass 5 -q 0 --quiet - $strFileName &

The script is called hourly from crontab so I get regular email with lame's messages. I want so save lame's messages to a log file instead of getting an email. I tried changing the command to:
sox -r 44100 -t ossdsp -w -s /dev/dsp -t raw -c 1 - | lame -s 44.1 -x -b 8 -m m --lowpass 5 -q 0 --quiet - $strFileName >> /root/record.log &
All that happens is that now there is an empty file named record.log but lame's messages still get emailed to me. I also tried editing the crontab and having the script's output redirected to >> /root/record.log but that doesn't work either.

How can I force lame to output its messages to a log file?
andrewstr is offline     Reply With Quote
Old 02-03-2004, 03:38 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 2,974
Thanked: 37
Hi.

You might want to try piping std error to your log file, put

2> /root/record.log

at the end of the lame command.

Dave
ilikejam is offline     Reply With Quote
Old 02-03-2004, 07:16 PM   #3
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 143
Thanked: 0

Original Poster
Dave, thanks for the tip. That does work but it overwrites the file every time.

How can I get it to append to the file? Will command 2>> logfile work?

Last edited by andrewstr; 02-03-2004 at 07:28 PM..
andrewstr is offline     Reply With Quote
Old 02-03-2004, 07:54 PM   #4
trickykid
Guru
 
Registered: Jan 2001
Posts: 23,977
Thanked: 8
Quote:
Originally posted by andrewstr
Dave, thanks for the tip. That does work but it overwrites the file every time.

How can I get it to append to the file? Will command 2>> logfile work?
Yeah, the >> should add to the end of the file specified.

Cheers.
trickykid is offline     Reply With Quote
Old 02-04-2004, 12:07 PM   #5
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 143
Thanked: 0

Original Poster
Thanks! That worked.

Why is it necessary to use 2> to direct the output? Why doesn't just > work?
andrewstr is offline     Reply With Quote
Old 02-04-2004, 12:13 PM   #6
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,483
Thanked: 0
> redirects STOUT to a new location. 2> redirects STERR to a new location.
stickman is offline     Reply With Quote
Old 02-04-2004, 12:37 PM   #7
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 143
Thanked: 0

Original Poster
What is the difference between STOUT and STERR?
andrewstr is offline     Reply With Quote
Old 02-04-2004, 12:54 PM   #8
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,483
Thanked: 0
STOUT = standard out
STERR = standard error

It's handy when the program you're running differentiates between "regular" output and "error" output.
stickman is offline     Reply With Quote
Old 02-04-2004, 01:44 PM   #9
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 143
Thanked: 0

Original Poster
Stickman, I understand the difference in the abbreviations but I was wondering why there are 2 types of output and how do you know the difference between the 2. Is the STOUT suposed to be for information and the STERR for error reporting? Is experimentation the only way to tell the difference?

I wonder if lame only uses STERR for it messages because it uses STOUT/STIN for compressed files.
andrewstr is offline     Reply With Quote
Old 02-04-2004, 02:48 PM   #10
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,483
Thanked: 0
It's really up to the author to determine what output goes in which direction. Theoretically, only output that from an error condition should go STERR. If it's not obvious what goes where, it may be in the man page for the program.
stickman is offline     Reply With Quote
Old 02-04-2004, 03:07 PM   #11
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 143
Thanked: 0

Original Poster
Doing some "googling," I found this link that is quite helpful:

http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
andrewstr is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
how to redirect the soundcard output to a file? jr0 Linux - General 2 10-31-2005 07:29 AM
How do I forward standard and error output into same file? ivj Linux - Software 5 07-19-2005 09:30 PM
How do I redirect sound card output to file ass0ciate Linux - Software 0 09-14-2004 04:41 PM
Redirect script output to log window in wxPython wapcaplet Programming 1 07-04-2004 09:59 PM
output from cpio won't redirect to file rawii Programming 5 01-27-2004 02:49 PM


All times are GMT -5. The time now is 06:37 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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration