How to Schedule Your Cron Jobs for Scheduled Tasks

What are Cron Jobs and why use it?

A cron job is a Linux command that schedules tasks for execution in the future. This is normally used to schedule regular tasks, such as sending out a notification every morning.

  • Allows OS to take scheduled backups of log files and databases.
  • Removes old log files
  • Archives and purges database tables
  • Sends out notifications, such as newsletters, Message of the Day (MOTD), or password expiration emails
  • Cleans up cached data regularly
  • Automates system maintenance

What is Cron Tab and How Do You Use it?

Cron derives its name from the Greek word Chronos, meaning time. This is a process that runs on the system automatically according to a schedule. Regular schedule tasks are run using its commands. Crontab is short for “cron table”. It allows you to perform tasks using the job scheduler, also known as cron.

  1. The time and date of execution.
  2. The script to be executed or called (this is called the command execution).
  3. The destination where the output of the command is stored. This could be placed in a system file or sent out as an email notification, for example.

What is the Linux Crontab format?

In Linux, there are six fields in the Contab. The first five columns define the time and date of the execution, and the sixth is used to specify the command’s execution.

This is the general formatting of a crontab. The first 5 columns are either denoted by an asterisk or a specified number given the field (NOTE: months of the year & days of the week could also be denoted with abbreviations, such as jan = January, tues = Tuesday in the last 2 columns). The sixth column is used for the command you would like to be executed using automation.
The crontab command with the -l (Lowercase L) option is used to list or manage the task for the current user.
The crontab command with the -e option is used to edit the crontab entry. You can edit crontab in editors such as vi, vim, nano, etc.
The crontab command with the -r option is used to remove complete scheduled jobs without confirmation from crontab.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store