![]() |
Cron job illustration |
Hello everyone! Good afternoon, and I hope you're
enjoying this lovely rainy day that I've been waiting for. I trust you're all doing well. We meet again for another
demonstration, and this time, I will be sharing some insights about Cron in Linux.
Let's get straight to the point!
What Is Cron?
Cron is a powerful time-based job scheduler in Unix-like operating systems, including Linux. It allows users and system administrators to schedule tasks or commands to run automatically at specified intervals. These tasks can include system maintenance, backups, or running scripts at designated times or intervals, such as daily, weekly, or monthly.
Cron operates in the background and relies on a configuration file called the crontab
(cron table), where users define the schedule and commands. Cron jobs are ideal for automating repetitive tasks,
saving time and effort while ensuring that important processes run regularly without manual intervention.
Understanding The Cron Syntax
![]() |
The format of the cron expression (my
documentation) |
For example, * * * * * would execute the job every minute of every hour, every day, every month, and every day of the week—essentially, it runs every minute without exception.
Setting Up My Script Auto_Backup.py Into Crontab
![]() |
Crontab editor |
1. Open the crontab file to edit crontab file, open the terminal and type:
crontab -e
2. Add a new cron job at the bottom of the crontab file, add a new line to schedule script. For example, to run the Auto_Backup.py script every minute, I would add:
* * * * * /usr/bin/python3 /path/to/Auto_Backup.py >> /path/to/cron.log 2>&1
Explanation:
- * * * * * specifies that the script should run every minute (you can adjust this according to your schedule).
- /usr/bin/python3 is the path to the Python 3 interpreter.
- /path/to/Auto_Backup.py is the full path to Python script.
- >> /path/to/cron.log 2>&1 ensures that the output and any errors are logged into a log file for monitoring.
After adding the cron job, save the file and exit the editor. The cron job will now be scheduled to run automatically according to the time interval you specified.
Delete Cron Job
1. Edit the crontab editor:
crontab -e
2. Find the line corresponding to the cron job you want to remove and delete it. For example:
* * * * * /usr/bin/python3 /path/to/script.py >> /path/to/cron.log 2>&1
Simply delete this line.
If you want to clear the entire crontab (delete all scheduled tasks), you can do so with:
crontab -r
3. Save and exit after deleting the line check the current crontab to confirm that the job has been removed:
crontab -l
Video Demonstration
For a complete demonstration and better understanding, you can watch this video:
End
I hope the video and insights I've shared will help anyone seeking a clear understanding. Thank you for visiting my blog, and I look forward to seeing you again in the next article and video! Have a great day!