LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-24-2015, 05:22 AM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 197

Rep: Reputation: 3
output to file not working


I am using mpg123 on raspbian to play mp3 files. I would like to create a log file showing which mp3 was played when. So I run this command in the terminal.

Code:
/usr/bin/mpg123 -Z /root/media/* 2>&1 | while read i; do echo "$(date): $i"; done | grep Playing
The output is this:
Code:
Thu Dec 24 12:17:36 EET 2015: Playing MPEG stream 2 of 5: test3.mp3 ...
Thu Dec 24 12:17:37 EET 2015: Playing MPEG stream 4 of 5: test5.mp3 ...
Thu Dec 24 12:17:39 EET 2015: Playing MPEG stream 3 of 5: test4.mp3 ...
Thu Dec 24 12:17:41 EET 2015: Playing MPEG stream 1 of 5: test2.mp3 ...
and its exactly what I want.

So now all I have to do is write this output to a file. To do that, I modify the command like this.

Code:
/usr/bin/mpg123 -Z /root/media/* 2>&1 | while read i; do echo "$(date): $i"; done | grep Playing >> /tmp/media.log
But all I get is an empty media.log file.

What I'm I doing wrong here?

Thanks
 
Old 12-24-2015, 08:10 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
How long have you let the code run before killing it?
I think the problem here is the large output buffer of grep. It will appear eventually, if you wait long enough to fill the output buffer. (Ctrl+C seems to kill the entire pipe without flushing it, though).
You can try running grep with the --line-buffered option and see if it helps.
 
Old 12-24-2015, 08:37 AM   #3
aristosv
Member
 
Registered: Dec 2014
Posts: 197

Original Poster
Rep: Reputation: 3
Thank you. --line-buffered resolved the issue.
 
  


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
Format diff output file, suppress-common-lines not working phoebes Linux - Newbie 4 12-17-2015 08:10 PM
Output in Log file instead of Standard Input Output srinietrx Programming 3 10-18-2015 10:34 AM
Redirect make output to file, make | tee not working jiobo Linux - Software 5 05-11-2014 11:43 AM
Standard script output to screen & -x option output to file BoBeau236 Programming 6 05-10-2011 08:43 AM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 08:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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