Skip to content

Instantly share code, notes, and snippets.

@henrytriplette
Last active March 2, 2019 23:44
Show Gist options
  • Save henrytriplette/fc8aba8b68dbb75f3efdf98b1319b3de to your computer and use it in GitHub Desktop.
Save henrytriplette/fc8aba8b68dbb75f3efdf98b1319b3de to your computer and use it in GitHub Desktop.
RaspberryPi: Python Script launch on boot

How to setup script autolaunch

Start from home base directory

nano launcher.sh

Then type

#!/bin/sh
# launcher.sh
# navigate to home directory, then to this directory, then execute python script, then back home

cd /
cd home/pi/instagramcounter
sudo python3 main.py
cd /

Cntl-X, Return to save.

1: Make It Executable

We need to make the launcher script an executable, which we do with this command

chmod 755 launcher.sh

Now test it, by typing in:

sh launcher.sh

This should run your Python code.

2: Add Logs Directory

Navigate back to your home directory:

cd

Create a logs directory:

mkdir logs

3: Add to Your Crontab

Type in:

sudo crontab -e

This will brings up a crontab window.

Now, enter the line:

@reboot sh /home/pi/instagramcounter/launcher.sh >/home/pi/logs/cronlog 2>&1

4: Reboot and See If It Works

Unplug the power or just type in:

sudo reboot

Wait for startup and see if your script automatically launches.

If it doesn't work, check out the log file:

cd logs
cat cronlog

This will show you any errors that you might have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment