Auto Run Raspberry Pi Script with Cron

It seems like there have problem if you want to auto run script on Raspbian Stretch by editing rc.local file. So, how about Cron?

INTRODUCTION

Cron is a tool for configuring scheduled tasks on Unix systems. It is used to schedule commands or scripts to run periodically and at fixed intervals. Tasks range from backing up the user’s home folders every day at midnight, to logging CPU information every hour.

Since editing rc.local have problem with the latest Raspbian Stretch, you can considering Cron to auto run your script on Raspberry Pi.

VIDEO

This video will show you how to auto run Raspberry Pi script on start.

EDITING CRONTAB

Run crontab with the -e flag to edit the cron table:

crontab -e

SELECT AN EDITOR

The first time you run crontab you’ll be prompted to select an editor; if you are not sure which one to use, choose nano by pressing Enter.

RUN A TASK ON REBOOT

To run a command every time the Raspberry Pi starts up, write @reboot. For example:

@reboot python /home/pi/myscript.py

This will run your Python script every time the Raspberry Pi reboots. If you want your command to be run in the background while the Raspberry Pi continues starting up, add a space and & at the end of the line, like this:

@reboot python /home/pi/myscript.py &

REFERENCES
  1. Scheduling Tasks with Cron

Buy

Thank you

Thank you for reading this tutorial. If you have any technical inquiry, please post at Cytron Technical Forum.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorail

Display Temperature and Humidity on OLED using DHT22 and Arduino
Getting Started With Teensy Using Arduino IDE
Night Light
Arduino Device Tracker Using GSM GPS SIM7600E Module
Chocolate Box with Touch Sensor and Arduino
Scroll to Top