Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rc.local file not working raspberry pi

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
like image 663
user2137452 Avatar asked Dec 19 '22 14:12

user2137452


2 Answers

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

like image 190
Ivan X Avatar answered Dec 31 '22 11:12

Ivan X


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 ;)

like image 29
Idriss Neumann Avatar answered Dec 31 '22 12:12

Idriss Neumann