LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 02-03-2004, 02:32 PM   #1
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 144

Rep: Reputation: 15
Question How to redirect standard output of piped command to log file


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?
 
Old 02-03-2004, 02:38 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
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
 
Old 02-03-2004, 06:16 PM   #3
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 144

Original Poster
Rep: Reputation: 15
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 06:28 PM.
 
Old 02-03-2004, 06:54 PM   #4
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 194Reputation: 194
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.
 
Old 02-04-2004, 11:07 AM   #5
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 144

Original Poster
Rep: Reputation: 15
Thanks! That worked.

Why is it necessary to use 2> to direct the output? Why doesn't just > work?
 
Old 02-04-2004, 11:13 AM   #6
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
> redirects STOUT to a new location. 2> redirects STERR to a new location.
 
Old 02-04-2004, 11:37 AM   #7
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 144

Original Poster
Rep: Reputation: 15
What is the difference between STOUT and STERR?
 
Old 02-04-2004, 11:54 AM   #8
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
STOUT = standard out
STERR = standard error

It's handy when the program you're running differentiates between "regular" output and "error" output.
 
Old 02-04-2004, 12:44 PM   #9
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 144

Original Poster
Rep: Reputation: 15
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.
 
Old 02-04-2004, 01:48 PM   #10
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
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.
 
Old 02-04-2004, 02:07 PM   #11
andrewstr
Member
 
Registered: Oct 2003
Location: WA--USA
Distribution: Red Hat 9, Suse 10.2
Posts: 144

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

http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
 
  


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are 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 06:29 AM
How do I forward standard and error output into same file? ivj Linux - Software 5 07-19-2005 08:30 PM
How do I redirect sound card output to file ass0ciate Linux - Software 0 09-14-2004 03:41 PM
Redirect script output to log window in wxPython wapcaplet Programming 1 07-04-2004 08:59 PM
output from cpio won't redirect to file rawii Programming 5 01-27-2004 01:49 PM


All times are GMT -5. The time now is 08:16 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 Google+: linuxquestions
Open Source Consulting | Domain Registration