4

This is the contents of my /etc/rc.local file. It is supposed to run on login on my raspberry pi, yet it just logs in in (as I'm using auto login) and then does nothing, i.e. it just sits there with pi@raspberrypi ~$_ waiting for a command. I have no idea why it's not working nor any experience with bash scripts.

It should mount a usb then run a file on said usb but it doesn't.

    #!/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.


    sudo /bin/mount /dev/sda1 /media/robousb
    sudo python media/robousb/Robopython/usercode_old.py

    exit 0
0

4 Answers 4

5

I assuming you're running Raspbian, which is pretty much Debian.

rc.local runs as root before login, so you don't need or want sudo; it may be causing an error, hence nothing happening.

User-level commands that run for any user when they log in (unlike rc.local, which runs before login) can be put into /etc/bash.bashrc. That may be more applicable to your situation, at least the second command.

Login commands for the pi user only can be put into /home/pi/.bashrc

Sign up to request clarification or add additional context in comments.

Comments

3

I have the same problem. In Raspbian forum is the solution:

Just change the first row from #!/bin/sh -e to

#!/bin/bash 

Ivan X is right. You don´t need sudo command.

1 Comment

This trick does not work for me on my Raspberry Pi 4B
2

I don't know raspberry-pi but you could try to write something into a file to see if the file is running or not. For example :

touch /tmp/test.txt
echo "$(date) => It's running" > /tmp/test.txt

If it doesn't work, I know that on some OS (fedora, rhel, centos for example), the path of that file is /etc/init.d/rc.local. It doesn't cost anything to try this path ;)

Comments

2

I have the exact same problem with RPi3/Jessie.

I suggest you to launch your script in the bashrc by doing

sudo emacs /home/pi/.bashrc

In my case i wrote at the EOF:

bash /home/pi/jarvis/jarvis.sh -b &

And that works well at each startup.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.