2

I have a script I want to run on startup (this is for a raspberry pi), and I've followed the instructions in the answer to the same question (linked here).

  1. The code I want to run is in a text file called startup.sh

  2. #!/bin/sh is in the first line of startup.sh. But when I run sudo startup.sh in the terminal to check whether the code is functioning, I get an error that says, "command not found". I get the same error when I run startup.sh

  3. In /etc/rc.local, I've written sh, then the full pathname to startup.sh followed by exit 0

    sh /home/bugs/Desktop/AutoBeetle-BeetleMonitoring/startup.sh
    

    exit 0

  4. verified that the first line in /etc/rc.local is #!/bin/sh -e

  5. ensured /etc/rc.local is executable:

    sudo chown root /etc/rc.local
    sudo chmod 755 /etc/rc.local
    
  6. verified that the code works:

    sudo /etc/rc.local start
    

When I do this, the code works perfectly. But when I re-boot the system, it still doesn't run on startup. I'm confused why everything works except step 2, and whether that's causing the problems with running on startup. Any help much appreciated.

muru
  • 207,228

2 Answers2

2

If all else fails, consider putting a line in root's crontab:

@reboot /home/bugs/Desktop/AutoBeetle-BeetleMonitoring/startup.sh

One final point, be sure anyone can run the script (ie. permissions 755 or better)

muru
  • 207,228
quill
  • 1,015
1

(I don't have enough Reputations to comment.) Try using the full path: /usr/bin/sudo followed by the full path to your script.

(And for maybe a bonus reputation point.) Use the 'which' command to display the full path: which sudo.