1

I am using mplayer. I want to send everything to a log file (/tmp/server.log), but I want the Volume output to be written to the terminal. I have seen that there is a way to split the output with tee, but I can't seem to get it to work. This is what I have so far:

$mplayer /path/to/song.wav 1>tee /tmp/server.log | grep Volume  2> /tmp/server.log

I want ALL of the stdout and stderr to go to the log file, but only the lines with Volume from stdout to be written to the terminal. Or is there a better way of doing this?

2

Assuming you are using bash and that "Volume" is not a word that appears on stderr:

 $ mplayer /path/to/song.wav 2>&1 | tee -a /tmp/server.log | grep -F Volume

This combines the stdout and stderr from mplayer (2>&1), appends (note the -a to /tmp/server.log and grep's all lines for the word Volume.

  • There's still some output, other than Volume lines that are slipping through. Is there another output I'm not aware of and not catching? – MrUser May 30 '14 at 11:06
  • @MrUser what is the actual output that you are seeing? I did not try this with mplayer, just with { echo "Volume 11" ; echo "error" 1>&2; } | tee .... – Anthon May 30 '14 at 13:03
  • The new output looks something like this: Line1: Volume: 9 % Line2: A: 12.0 (12.0) of 104.0 (01:44.0) 0.2% The second line isn't the worst thing in the world, but at this point it would be an exercise to see if I could get rid of it. – MrUser Jun 2 '14 at 11:37
1

Try this. Assuming bash

$ mplayer /path/to/song.wav 2>> /tmp/server.log | tee -a /tmp/server.log | grep Volume

here I am first appending stderr to file and passing only stdout to tee and using grep from there.

This removes Anthon's assumption of Volume not in stderr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.