I've made a FM radio transmitter using the tutorial from Make: http://makezine.com/projects/pirate-radio-throwies/

Everything worked perfectly until I got to step 7 (Run PiFM at Startup). I wrote the pirateRadio.sh script as described (see below), but when I added it to the startup scripts default profile (sudo update-rc.d pirateRadio.sh defaults), it gave me a lsb tags error. I rebooted the Pi, and now it just sits at a black screen after boot up and plays one sec of the music on repeat.

I appreciate any help in advance to either get me back into my pi and/or getting the script to work and run on boot. THANK YOU!

UPDATE: I've been able to get into my SD card and delete the pirateRadio.sh file, giving me access back to my Pi. Meaning, it's got to be somewhere in this code for the pirateRadio.sh file:

case "$1" in
        echo "StARRRRRRRting Pirate Radio"
        sudo /usr/bin/mpg123 -4 -s -Z /home/pi/Music/* | sudo /home/pi/pifm/pifm - 90.5

        echo "Stopping Pirate Radio"
        sudo killall pifm
        echo "Usage: /etc/init.d/pirateRadio.sh start|stop"
        exit 1

exit 0
  • Any idiot who instructs you to use sudo in an init script should be ignored.
    – goldilocks
    Commented Feb 10, 2017 at 13:35
  • @goldilocks Appreciate the sentiment, but any idea on how to make it work?
    – AgentOahu
    Commented Feb 10, 2017 at 17:59

1 Answer 1


First, get rid of that init script and forget about it. It's pointless in light of what it means to achieve, in addition to having been written by someone who do not understand how to achieve it properly in the first place.

You can just stick stuff like this in /etc/rc.local -- first check there's a PATH set at the top there already. If not:

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

If you don't understand what that is about, find out.

Also, change the shebang at the top to #!/bin/bash. It's probably just sh. This doesn't make much difference beyond allowing for a lazy style of output redirection (the exec &>> line below). Then add:

  exec &>> /var/log/my_rc_local.log
  mpg123 -4 -s -Z /home/pi/Music/* | /home/pi/pifm/pifm - 90.5 
) &

The parentheses indicate a subshell, another shell process that is forked off with &. One way or another, forking to the background is an absolute necessity for processes started by init. If not, init will kill them within 5-10 seconds.

Note such processes are by default run with superuser privileges which is why sudo is at best redundant.

Any output, including from the subshell itself, should be added to /var/log/my_rc_local.log. This means even if those other commands don't exist, have the wrong permissions, etc., the shell's error will be reported ("Unknown command", "permission denied", etc).

If the command is executed and does not produce any output, the log file will still get created but it will be empty.

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.