M-_-TD
Posts: 2
Joined: Thu Jan 03, 2019 3:46 pm

rc.local not working

Thu Jan 03, 2019 4:02 pm

Hi all,

I'm new to this forum but i do have some experience with the raspberry pi. I am using the raspberry pi zero v1.3 for this project. i am using ssh to edit things on my pi if that makes a difference. the goal of my project is to make an fm transmitter with the raspberry pi zero that works when i give it power. i got the radio transmission working by following this tutorial on youtube: https://www.youtube.com/watch?v=GXedC5dQyNk. all i needed to do on my own is make it work on boot but i can't get it to work. i am using rc.local and this is what my rc.local looks like right now.

Code: Select all

#!/bin/sh -e
#
#rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sudo /home/pi/radio/fm_transmitter-master/fm_transmitter -f 88.3 -r ~/radio/fm_transmitter-master/Fallout_\ New\ Vegas\ with\ Mr.\ New\ Vegas\ -\ Radio\ Narration\ and\ Soundtrack\ OST\ \ \ Tracklist\ \(320\ \ kbps\).wav &

exit 0
i know for a fact that this line is working:

Code: Select all

sudo /home/pi/radio/fm_transmitter-master/fm_transmitter -f 88.3 -r ~/radio/fm_transmitter-master/Fallout_\ New\ Vegas\ with\ Mr.\ New\ Vegas\ -\ Radio\ Narration\ and\ Soundtrack\ OST\ \ \ Tracklist\ \(320\ \ kbps\).wav &
i have even followed Make:'s tutorial for the "raspberry pi pirate radio throwie" but i couldn't get that to work on boot either.
does anyone have a clue what i'm doing wrong?

thanks in advance,

M-_-TD

epoch1970
Posts: 3661
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: rc.local not working

Thu Jan 03, 2019 6:56 pm

Rc.local is executed as root, you don’t need “sudo”.

(To execute your code in a better controlled context, you could write instead a custom systemd unit file, and leave rc.local alone. Unit files are the way to go with systemd-based OSes like Raspbian.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

fbe
Posts: 518
Joined: Thu Aug 17, 2017 9:08 pm

rc.local is working

Thu Jan 03, 2019 7:05 pm

Programs started from rc.local have root privileges by default. "sudo" is not needed here. You may use "sudo -u pi ..." if you want to run your program as pi from rc.local.
Replace ~/radio/... by /home/pi/radio/...

JumpZero
Posts: 1017
Joined: Thu Mar 28, 2013 7:35 pm
Location: 127.0.0.1

Re: rc.local not working

Thu Jan 03, 2019 7:16 pm

Hi
~/ refers to the user home directory so when it's run by root (as it is in rc.local) it's : /root
when you type the command as the user pi (even with sudo) it's /home/pi
So in your rc.local you better replace ~/ by the full path name (in your case it should be /home/pi I suppose)
As mentioned by others sudo is not needed in rc.local
Also be informed that before systemd (now standard in Raspbian) with "system V" rc.local was the last script run at boot time. It's not the case anymore because systemd launch everything in parallel. So in some cases, for instance if you need network in your rc.local, the network may not be ready yet and your rc.local fails... If you don't need network then no problem

M-_-TD
Posts: 2
Joined: Thu Jan 03, 2019 3:46 pm

Re: rc.local is working

Thu Jan 03, 2019 7:21 pm

fbe wrote:
Thu Jan 03, 2019 7:05 pm
Programs started from rc.local have root privileges by default. "sudo" is not needed here. You may use "sudo -u pi ..." if you want to run your program as pi from rc.local.
Replace ~/radio/... by /home/pi/radio/...
replacing ~/radio/... with /home/pi/radio/... helped and it works right now. but now i have the problem that the signal stutters, but the cpu isnt fully utilized. ill try and figure this one out on my own, but help is always welcome!

thanks fbe and thanks everyone else for their time! ; )

Return to “General discussion”