Create Your First Cron Job in Crontab
Here are some examples of the Crontab commands:
crontab -l # lists all cronjobs
crontab -e # edit cronjob
crontab -r # delete cronjobs
Clearing jobs from Crontab
We can clear all cron jobs using crontab with just a single command:
crontab -r
This is demonstrated in the following image
Checking Job Schedule
The schedule of the cronjobs can be found by running the following command:
crontab -l
It gives all the details of the cron job including name, schedule, and command.
Checking the validity of a cron job
Cron logs each attempt to execute a command in Syslog. We can validate that our job is scheduled properly by grepping syslog for the name of the command. We just need to run this command:
grep /home/Desktop/freeMemory.py /var/log/syslog
This will return a good response if the cron job was valid and executed without any error and will return an error if it failed for some reason. This also refreshes the output after the job runs every time.
Managing Cron Jobs Using Python
Here, we will discover the significance of cron jobs and the reasons you require them in this lesson. You will examine python-crontab, a Python module that allows you to communicate with the crontab.