Tools for Regular Operations
114
Jobs are defined by specifying the parameters that are relevant
to the execution period, the user that will be executing the job (except for user crontabs), and the command to execute, as illustrated in the following code
snippet Run the hourly jobsSHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
01 * * * * root run-parts /etc/cron.hourly
By looking at the standard /etc/crontab file, we can check the meaning of each field, as follows 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 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * username
command to be executedBased on this, if we check the initial example, 01 * * * * root run-parts /etc/
cron.hourly, we can deduce the following Run at minute 01
• Run every hour Run everyday Run every month Run everyday of the week Run as root Execute the run-parts /etc/cron.hourly command
This, in brief, means that the job will run on the first minute of every hour as the root user and will run any script located in that folder.
Sometimes, it is
possible to see an indication, such as number, which means that the job will be executed every multiple of that number. For example, */3 will run every 3 minutes
if it is on the first column, every 3 hours if it’s on the second, and so on.
Scheduling
tasks with cron and systemd115
Any command we might execute from the command line can be executed via cron, and the output will be—by default—mailed to the user running the job. It is a common practice to either define the user that will receive the email via the MAILTO variable in the crontab file or to redirect them to the appropriate log files for the standard output and standard error (stdout and stderr).
Share with your friends: