Cron jobs help you run commands or scripts automatically at set times. This saves you from doing repetitive tasks manually.
0
0
Cron jobs for scheduled tasks in Raspberry Pi
Introduction
You want to turn on a light every day at 7 PM.
You need to back up files every night without forgetting.
You want to check your system status every hour.
You want to run a script to update weather info every morning.
You want to clean temporary files every week automatically.
Syntax
Raspberry Pi
minute hour day_of_month month day_of_week command_to_run
Each part is a number or symbol that tells when to run the command.
Use * to mean 'every' for that time part.
Examples
Runs the script at 7:00 AM every day.
Raspberry Pi
0 7 * * * /home/pi/turn_on_light.sh
Runs backup script at 10:30 PM every Monday.
Raspberry Pi
30 22 * * 1 /home/pi/backup.sh
Runs the status check every 15 minutes.
Raspberry Pi
*/15 * * * * /home/pi/check_status.shSample Program
This example shows how to edit the cron table to schedule a script. You open the cron editor, add a line with the time and command, then save it.
Raspberry Pi
# Open terminal on Raspberry Pi crontab -e # Add this line to run a script every day at 8 AM 0 8 * * * /home/pi/myscript.sh # Save and exit the editor # The script /home/pi/myscript.sh will run automatically at 8 AM daily
OutputSuccess
Important Notes
Make sure your script has execute permission: chmod +x /home/pi/myscript.sh
Use full paths in your scripts because cron runs with limited environment.
Check cron logs if your job does not run: grep CRON /var/log/syslog
Summary
Cron jobs automate tasks by running commands at scheduled times.
Use the crontab editor to add or change cron jobs.
Always test your scripts manually before scheduling them.