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

Removing cron jobs

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 job schedule

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.

Grep syslog for cron job validity

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.

Similar Reads

What are Cron and Crontab?

The utility known as Cron enables users to automatically run scripts, commands, or applications according to a predetermined schedule. The file called Crontab contains a list of the jobs that will be run by Corn....

Create Your First Cron Job in Crontab

Here are some examples of the Crontab commands:...

Create a new Cronjob with Python using subprocess

For example, we want a job that tells how much memory is being used and how much is free at that moment after every 1 hour. We first need to create a job file that will execute this:...

Contact Us