CentOS command-crontab: Job Scheduling
Cron is a Linux scheduled execution tool that can run jobs without human intervention. The cron daemon reads the crontab file and executes the task at the specified time according to the configuration.
The contab command is used to add, delete, and display a cron task table.
(Ubuntu environment) You can use the service command to start and stop the cron service:
Service cron status # view the cron service status
Service cron start # start the cron service
Service cron stop # stop the cron service
Service cron restart # restart the cron service
Service cron reload # reload the cron service configuration
Crontab command Command Format
Crontab [-u user] file
Crontab [-u user] [-l |-r |-e] [-I] [-s]
Command Parameters
-U
Specified user
-L
Displays the contents of the current crontab file.
-R
Delete the contents of the current crontab file.
-E
Edit the content of the current crontab file. If the file does not exist, create a new file.
-I
A prompt is displayed when you delete the crontab file.
Crontab file
Format: minute hour day_of_month month day_of_week command
Field description
Field descriptionMinute, value range: (0-59) hour, value range: (0-23) day_of_month date, value range: (0-31) month, the value range is (1-12). You can also use jan, feb, mar, apr... day_of_week week. The value range is (0-6). The value is 0 or 7 on Sunday, or sun, mon, tue, wed, thu, fri, sat indicates the command to be executed by the command
Special symbol meaning
Special symbol description* For all possible values, specify the value list, for example, 1, 3, 5, 7, 9-specify the Integer Range, for example, 1-5/Specify the Interval Frequency.
Cron expression example
Example*/15 * execute the task 0 */2 * every 2 hours every 15 minutes, execute the task 0 3 * at every day on the hour. Execute the task 0 0, 5, 15, 25 * on the 5 th and 15 th of each month, task execution at AM on the 25 th is between and every Monday, execute the task on the hour or on the hourInstance
A) add a cron task
huey@huey-K42JE:~/huey/linux/cmdline$ echo "*/3 * * * * date >> ~/huey/linux/cmdline/cron.out" > mycronhuey@huey-K42JE:~/huey/linux/cmdline$ crontab mycron
B) delete a cron task
huey@huey-K42JE:~/huey/linux/cmdline$ crontab -r
C) display cron tasks
huey@huey-K42JE:~/huey/linux/cmdline$ crontab -l*/3 * * * * date >> ~/huey/linux/cmdline/cron.out