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

A simple method for running commands automatically on boot.
Zach Zach (236)
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. When you buy through links on our site, we may earn a small affiliate commission at no cost to you.

To run basic commands or auto-run programs on 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
Keep an eye on your temperatures.
20 minutes

There are several IR camera sensors now available to electronics hobbyists that allow you to measure thermal radiation.