I'm using this in as my /etc/init.d/pirateRadio.sh

the Radio does play a wav with this in the rc.local

export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/sbin:/usr/bin
sleep 10
 exec &>> /var/log/my_rc_local.log
 cd /home/pi/pifm/pifm && ./pifm left_right.wav 100.1 stereo
) &

I had the led working before I added the above by itself in the rc.local

# Light ON AIR LED
sudo python /home/pi/pifm/pifm/ledon.py &

but now I am trying to combine both, in a shell and i am lost. I usually get [src/libout123/wav.c:755] error: flushing failed: Broken pipe

This is what I have craeted for pirateRadio.sh

# /etc/init.d/pirateRadio.sh
# Provides:              pirateRadio.sh
# Required-Start:        $remote_fs $syslog
# Required-Stop:         $remote_fs $syslog
# Default-Start:         2 3 4 5
# Default-Stop:          0 1 6
# Short-Description:     Runs radio
# Description:           Runs my radio.

export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/sbin:/usr/bin
sleep 20

# This works in the rc.local
# (
#  exec &>> /var/log/my_rc_local.log
#  cd /home/pi/pifm/pifm && ./pifm - 100.1
# ) &

case "$1" in
        echo "StARRRRRRRting Pirate Radio"
        sudo /usr/bin/mpg123 -4 -s -Z /home/pi/Music/* | cd /home/pifm/pifm/ && sudo ./pifm - 100.1
        echo "Stopping Pirate Radio"
        killall pifm
        echo "Usage: /etc/init.d/pirateRadio.sh start|stop"
        exit 1

# Light ON AIR LED
sudo python /home/pi/pifm/pifm/ledon.py &

exit 0

Oh and additionally, if I correct, "esac" to "case" I get

sudo ./pirateRadio.sh start
./pirateRadio.sh: line 37: syntax error near unexpected token `newline'
./pirateRadio.sh: line 37: `case '

1 Answer 1


You are piping the output of mpg123 into cd. This won't work as intended. cd before the pipeline, or simply use an absolute path to your pifm script.

If you absolutely have to cd and want to have your main script stay in the same directory, open a sub-shell with parantheses ( commands … ).

Oh, and additionally, you don't correct esac to case. That's reversed intentionally, it's the end of case, just as fi is the end of if. Oddly do/done do not follow this convention.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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