Crontab: How to Run a Simple Command When Your Raspberry Pi Boots

A simple method for running commands automatically on boot.
Zach Zach (248)
2 minutes

This short guide will show you how to execute a simple command automatically when your Raspberry Pi boots up. There are several methods for doing this, but for executing basic commands and running scripts without many dependencies, crontab is the easiest method.

This method is recommended for basic commands where you don't need to wait for specific system resources to become available.

Raspberry PiRaspberry Pi ×1

Howchoo is reader-supported. As an Amazon Associate, we may earn a small affiliate commission at no cost to you when you buy through our links.

To run basic commands or auto-run programs on Raspberry Pi OS (formerly Raspbian) boot, we'll use crontab. crontab can be used to run commands on boot or at a specific time interval.

First, connect to your Raspberry Pi.

Then, open crontab:

crontab -e

When prompted, I recommend choosing the Nano editor to edit the crontab.

At the bottom of the file, add the following @reboot entry:

@reboot [your command here]

Run a Python script on Raspberry Pi boot

For example, this command runs a Python script automatically on system boot:

@reboot python /home/pi/

When you're done, save the file and exit.

To run a command containing sudo, you'll need to edit the root user's crontab instead:

sudo crontab -e

Then, you can do:

@reboot sudo python /home/pi/

If your script isn't executing, check the system log for cron events:

grep cron /var/log/syslog
John John (304)

There are some fundamental git commands that you will use frequently that are hard to work into a "how-to" guide. Here are some basic git commands and how to use them. These are in no specific order.