All Posts All Posts

Linux Essentials: Cron Job Management

October 30, 2017·
Software Engineering
·1 min read
Tecker Yu
Tecker Yu
AI Native Cloud Engineer × Part-time Investor

Cron allows us to create scheduled tasks in Linux. It is a built-in system service that enables repetitive task execution at specified time intervals by adding custom configurations.

crontab

By executing this command, we can load our crontab file into /var/spool/cron/crontabs.

File format:

13 04 * * * Command

The first five columns from left to right represent minute, hour, day, month, and weekday respectively. The asterisk means every.

Separators:

, represents separated time points, such as: 00 10,12 * * * means 10 AM and 12 PM every day

- represents time range, for example: 00 10-12 * * * means every full hour from 10 AM to 12 PM daily

*/n represents every n units of time, such as: */5 * * * * means every 5 minutes

It’s worth noting that the executable files to be run need to use absolute paths

For example: 13 04 * * * /etc/init.d/smb restart

Common parameters

$ crontab -l // List tasks
$ crontab -r name // Delete task file
$ crontab -e // Modify and install task file, enter editor, save and exit after editing to complete successfully

If you need one-time task scheduling for a specific moment, you can use the at command.

Views