I am trying to use tail -f and play a sound everytime a new line appears.

I tried this:

for i in tail -f myFile; do aplay alert.wav; done;

Which kinda worked, the output is:

Playing WAVE 'alert.wav' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Playing WAVE 'alert.wav' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Playing WAVE 'alert.wav' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono

But after 3 times it stops, and I would like to print the tail -f result and not the aplay result.

How could I achieve that?

link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

I'm not on a Linux right now, but it should work like this:

tail -f yourFile | while read line ; do aplay alert.wav 2>&1 1>/dev/null ; echo $line ; done

On Mac OS X, I'm using the following successfully to print the system log:

tail -f /private/var/log/system.log | while read line; do printf "\a" ; echo $line ; done
link|improve this answer
Thanks it does work, I added aplay -q so it wont show the aplay results. – foralsa May 8 '11 at 18:51
@foralsa Thanks. Since I don't know anything about aplay I just redirected its output. Should also work. – Daniel Beck May 8 '11 at 18:51
feedback

Your Answer

 
or
required, but never shown

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