Running Shell Script After Boot on Raspberry Pi

Running Shell Script after boot on Raspberry PI

The reason it wasn't working was because the script needed to be run as the user pi.

I changed the code in the rc.local script to this: su - pi -c "bash /home/pi/logon.sh &"

This makes the script run as the user pi and the ampersand is used to make the script run separate to the rc.local script by forking it. (http://hacktux.com/bash/ampersand)

How to run a shell script at startup

The file you put in /etc/init.d/ have to be set to executable with:

chmod +x /etc/init.d/start_my_app

As pointed out by @meetamit, if it still does not run you might have to create a symbolic link to the file in /etc/rc.d/

ln -s /etc/init.d/start_my_app /etc/rc.d/

Please note that on the latest versions of Debian, this will not work as your script will have to be LSB compliant (provide at least the following actions: start, stop, restart, force-reload, and status):
https://wiki.debian.org/LSBInitScripts

As a note, you should always use the absolute path to files in your scripts instead of the relative one, it may solve unexpected issues:

/var/myscripts/start_my_app

Finally, make sure that you included the shebang on top of the file:

#!/bin/sh

Start shell script on Raspberry Pi startup

Make sure the program is executable

chmod +x filename.py

open /etc/rc.local in your editor of choice

sudo nano /etc/rc.local

and add

python /FULL PATH TO SCRITP/filename.py

before the exit

shell script works, but not on boot. [Raspberry pi]

The answer is that contab runs applications as root and therefore the packages have to be installed with sudo

sudo pip install pandas 

solved the problem.
Shoutout to CoderMike

Raspberry Pi doesn't run script on autostart

The Problem is that you have to use absolute pathes to the scripts. Using /home/pi/Dektop/s0.sh and so on will work



Related Topics



Leave a reply



Submit