
Automate with Ease with crontab
Welcome to the world of seamless automation with your Raspberry Pi. In this guide, we’ll explore how to automatically launch Python scripts at system boot, allowing your Raspberry Pi to kickstart tasks and projects as soon as it powers on.
Harness the Power of Boot-Time Automation:
Imagine your Raspberry Pi as a reliable, self-sufficient tool, ready to execute Python scripts the moment it boots up. Whether it’s initializing sensors, launching data logging routines, or setting up IoT devices, this level of automation opens a realm of possibilities.
Python Script
First, we need to have a Python script. If you already have one created that you need to start at boot up great! you can use that, if you simply just want to follow along with the guide and have no specific project in mind then just copy the basic Python script below.
Basic Blink.py
import RPi.GPIO as GPIO
import time
blinkLED=11
GPIO.setmode(GPIO.BOARD)
GPIO.setup(blinkLED, GPIO.OUT)
for i in range(10):
GPIO.output(blinkLED,GPIO.HIGH)
time.sleep(.5)
GPIO.output(blinkLED,GPIO.LOW)
time.sleep(.5)
GPIO.cleanup(
Building the Circuit
The connections are very simple:
- Connect the long leg of the LED to GPIO17 (pin 11) using a 220 Ohm current limiting resistor to protect the LED.
- Connect the short leg of the LED to GND

Creating a Bash Script
Open the Raspberry Pi terminal and type:
sudo nano blink.sh
Of course, if you are doing this for your own project, you should name it accordingly.
Now with the nano editor opened add these following lines:
#!/bin/sh
# blink.sh
cd /
cd home/pi/Blink/
sudo python blink.py
cd /
Save the file with ctrl + s, then close the editor with ctrl + x.
You can confirm your bash script contents using:
cat blink.sh
That will print the bash script contents to the terminal.
Now we need to make the bash script executable. In the terminal type:
sudo chmod 755 blink.sh
Test everything works by typing:
sh blink.sh
If the Blink program starts running everything is good to go.
It’s a good idea to have a log, just in case there are any issues while trying to run the program at boot up. To create a logs directory, type the following in the terminal:
sudo mkdir logs
Starting the script with crontab
Now we need to add the bash script to the boot process. In terminal type:
sudo crontab -e
If this is the first time using crontab, you will be prompted to select which editor you want to use, select the nano editor to open the file with nano.
Scroll all the way down to the bottom of the file and add the following line:
@reboot sh /home/pi/blink.sh >/home/pi/logs/cronlog 2>&1
Press ctrl + x
to close the file, make sure to save it by pressing y
when prompted to do so then hit Enter
to confirm.
Now reboot your Raspberry Pi and the blink.py will automatically start running.
Conclusion
With the power to start Python scripts at boot, your Raspberry Pi evolves into a self-sufficient, versatile tool, perfectly aligned with your goals and projects. The possibilities are vast, and the execution is seamless.
Imagine your Raspberry Pi as your trusty assistant, always at the ready, always on time. With crontab
boot tasks, you define the rules, and your Raspberry Pi plays by them. So, power up your Raspberry Pi, and let the automated magic begin.
That’s All Folks!
You can explore more of our Raspberry Pi guides here: Raspberry Pi for Beginners
Unlock the Possibilities
We have put together a list of some great Raspberry Pi products and deals: Shop Raspberry Pi Goodies Now!