The crontab command is used in linux systems to set periodically executed commands. The crontab file contains a series of jobs and commands sent to the cron daemon. Each user can have their own crontab file. At the same time, the operating system saves a crontab file for the entire system, which is usually stored in subdirectories under/etc or/etc, this file can only be modified by the system administrator.
Each row of the crontab file complies with a specific format and is separated by spaces or tabs into several fields. Each field can contain one or more values.
Parameters:
1. crontab-l list the current crontab task
2. crontab-d: Delete the current crontab task.
3. crontab-e: edit a crontab task
4. Use filename as the task list file of crontab and load it
Crontab format:
Rows in the crontab file are composed of six fields. Different fields are separated by spaces or the tab key. The six fields are:
Minute (0-59) hour (0-23) Date (1-31) month (1-12) day of the week (0-6, where 0 represents Sunday) command
MIN HOUR DAY MONTH DAYOFWEEKCOMMAND
Example 1: #06:10 every day
10 6 **** date
Example 2: # every two hours
0 */2 * date
Example 3: # every two hours from PM to am, am
0 23-7/2, 8 **** date
Example 4: # am on the 4th day of each month and from Monday to Wednesday of each week
0 11 4*1-3 date
Example 5: #, January 1, January 1
0 4 11 * date
Note: When Using crontab, the environment variables that can be accessed in the running script may not be consistent with those in the current test environment, it is safer to set the environment variable (export) in the running script program)
Run as a file:
(1ndcreate a file named crond.txt as follows and restart it at 05:36 every morning.
36 5 * reboot
(2) upload to the/opt directory
(3) run the command
Crontab/opt/crond.txt
Crontab-l
Make the configuration file take effect: If the configuration file takes effect, you have to restart crond. Remember that since the crond configuration file under each user is modified. Restart the crond server.
Scheduled task start: [start stop status restart]
[Root @ localhost ~] #/Etc/init. d/crond start // method 1
[Root @ localhost ~] # Service crond start // method 2
If you want crond to run at startup, you should change its running level;
[Root @ localhost ~] # Chkconfig -- levels 35 crond on