Cron Daemon, Table and Jobs

This section describes what is cron daemon and its related cron tables/jobs.

What Is a Cron Job? - A cron job is a task scheduled to be executed at specific times.

On a Linux system, there are 4 components involved in managing and executing cron jobs.

1. Cron Daemon, "crond" - The process that runs cron jobs according their scheduled times.

2. System Cron Table, "/etc/crontab" - The system file that defines cron jobs and their execution times.

3. User Cron Tables, "/var/spool/cron/*" - User files that defines cron jobs and their execution times for each user.

4. Cron Table Manager, "crontab" - The command to manage user cron tables.

Here is what I did to view the Cron Daemon and the Cron Table on my CentOS 8 computer.

1. The cron daemon, "crond", should be launched at the system startup time and runs forever.

herong$ ps -elf | grep crond
F S UID    PID  PPID  C PRI  STIME TTY      TIME CMD
4 S root  1724     1  0  80  13:46 ?    00:00:00 /usr/sbin/crond -n

2. The system cron table, "/etc/crontab", should be empty on a new computer.

herong$ sudo more /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,...
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

3. Add a cron job in my own cron table by running the "crontab -e" command in a system default editor.

herong$ crontab -e

# Run it at 06:00 every day
0 6 * * * echo "Time to wake up!" > /dev/null

4. View the cron table of a given user.

herong$ sudo crontab -l -u herong

# Run it at 06:00 every day
0 6 * * * echo "Time to wake up!" > /dev/null

Cron Job Scheduling Syntax - As you can see from the system cron table file, the cron job scheduling syntax supports 5 parameters for 5 time components: minute, hour, date, month, day-of-week.

Cron job scheduling parameters work together based on the following rules:

Each scheduling parameter supports 5 syntaxes:

Here are some nice examples of cron job schedules:

0 6 * * * echo "Time to wake up!" > /dev/null
0 0 1 * * echo "Happy first day of the month!" > /dev/null
0 8,19 * * * echo "Take it twice a day!" > /dev/null
*/10 * * * * echo "Check Website every 10 minutes..." > /dev/null
*/5 7-9,16-18 * * 1-5 echo "Every 5 minutes in rush hour ..." > /dev/null

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

Process Management

 "ps" - Display Current Processes

 "jobs" - Manage Background Jobs

Cron Daemon, Table and Jobs

 "tmux" - Terminal Multiplexer

 Files and Directories

 Users and Groups

 File Systems

 Block Devices and Partitions

 LVM (Logical Volume Manager)

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Software Package Manager on CentOS - DNF and YUM

 vsftpd - Very Secure FTP Daemon

 Postfix - Mail Transport Agent (MTA)

 Dovecot - IMAP and POP3 Server

 Email Client Tools - Mail User Agents (MUA)

 LDAP (Lightweight Directory Access Protocol)

 Administrative Tasks

 References

 Full Version in PDF/EPUB