The crontab service requires root permissions. The following is an official explanation: SHELL =/bin/bashPATH =/sbin:/bin:/usr/sbin: /usr/binMAILTO = rootHOME =/# Fordetailsseeman4crontabs # Exampleofjobdefinition:
The crontab service requires the root permission for execution.
The following is an official explanation:
SHELL =/bin/bash
PATH =/sbin:/bin:/usr/sbin:/usr/bin
MAILTO = root
HOME =/
# 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, tue, wed, thu, fri, sat
# |
# ***** User-name command to be executed
The usage is as follows:
New scheduling task
Run the crontab-e command to edit the scheduled task to be executed. you can also edit the content in the/etc/crontab file. The example is as follows: ceshi in this example. sh is the script stored in the/root directory.
* ***/Root/ceshi. sh: execute ceshi. sh once per second
30 5 ***/root/ceshi. sh execute ceshi. sh at 05:30 every day
** 1 1 */root/ceshi. sh: execute ceshi. sh every month on January 1, January 1.
30 5 */10 ** root/ceshi. sh run ceshi. sh at 05:30 every 10 days.
30 5 ** 1/root/ceshi. sh run ceshi. sh every Monday 05:30
View scheduled tasks
Run: crontab-l
Delete a scheduling task
Run: crontab-r
Save the output result of the scheduling task
Add>/path/file 2> & 1 after the task
For example
30 5 */10 ** root/ceshi. sh>/root/record.txt 2> & 1
Note: 2> & 1 redirects all execution results to the target file.