/Sbin/service crond start // start the service
/Sbin/service crond stop // close the service
/Sbin/service crond restart // restart the service
/Sbin/service crond reload // reload the configuration
This service can be automatically started when the system is started:
Add:
/Sbin/service crond start
1. directly use the crontab command to edit
The cron Service provides the crontab command to set the cron service. The following are some parameters and descriptions of this command:
Crontab-u // set a user's cron service. Generally, the root user needs this parameter when executing this command.
Crontab-l // list the details of a user's cron Service
Crontab-r // Delete the cron service of no user
Crontab-E // edit a user's cron Service
For example, to view your cron settings as root:
Crontab-u root-l
For example, Root wants to delete Fred's cron settings:
Crontab-u Fred-R
When editing the cron service, the edited content has some formats and conventions. Enter:
Reference:
Crontab-u root-e
In the VI editing mode, the edited content must conform to the following format:
*/1 ***** ls>/tmp/ls.txt
The first part of this format is the time setting, and the last part is the command to be executed. If there are too many commands to be executed, you can write these commands into a script, then you can directly call this script here. Remember to write the complete path of the command during the call. We have a certain agreement on the time setting. The first five * numbers represent five numbers. The value range and meaning of the numbers are as follows:
Reference:
Minutes (0-59)
Hour (0-23)
Date (1-31)
Month (1-12)
Week (0-6) // 0 represents Sunday
In addition to numbers, there are also several special symbols: "*", "/", "-", * representing all numbers in the value range, "/" indicates the meaning of each, "*/5" indicates every five units, "-" indicates the number from a number to a number, "," separate several discrete numbers. The following examples illustrate the problem:
Reference:
Every morning
0 6 *** echo "Good morning. ">/tmp/test.txt // note that no output is visible from the screen with pure echo, because cron has emailed any output to the root mailbox.
Every two hours
0 */2 *** echo "have a break now.">/tmp/test.txt
Every two hours from PM to am, am
0 23-7/2, 8 *** echo "have a good dream :)">/tmp/test.txt
Am from Monday 4 to Wednesday every week
0 11 4*1-3 command line
Am, January 1, January 1
0 4 1 1 * command line
2. Edit the configuration cron in the/etc/crontab file.
The cron service not only reads all files in/var/spool/cron every minute, but also reads/etc/crontab once. Therefore, we can use the cron service to configure this file. Crontab configuration is intended for a user, and editing/etc/crontab is a system task. The file format of this file is:
Shell =/bin/bash
Path =/sbin:/bin:/usr/sbin:/usr/bin
Mailto = root // if an error occurs or data is output, the data is sent to this account as an email.
Home =/
# Run-Parts
01 *** root run-parts/etc/cron. Hourly // run the script in/etc/cron. Hourly every hour.
02 4 *** root run-parts/etc/cron. daily // run the script in/etc/cron. daily once a day.
22 4 ** 0 root run-parts/etc/cron. Weekly // run the script in/etc/cron. Weekly once a week.
42 4 1 ** root run-parts/etc/cron. Monthly // run the script in/etc/cron. Monthly every month.
User running path
Note the "run-parts" parameter. If this parameter is removed, you can write a script name to run, instead of the folder name.