Crontab is a convenient way to regularly (cyclically) execute a task on Unix/Linux systems.Program
Use the cron service and use the service crond status to view the cron service status. If it is not started, the Service crond start starts it,
The cron service is a regular execution service. You can use the crontab command to add or edit tasks that require scheduled execution:
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 another 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 crontab-u root-e.
In VI editing mode, the edited content must conform to the following format: */1 ***** ls>/tmp/ls.txt
Edit the/etc/crontab file and add a line at the end: 30 5 * root init 6 so that the system is configured to automatically restart at every morning.
You need to set crondServices automatically started after the system startsIn/etc/rc. d/rc. Local, add
Service crond start
If you need to load other services when the system starts, you can continue to add the startup commands for other services.
For example, service mysqld start
Format:
Each row of the crontab file consists of six fields (Minutes, hours, day of month, month, day of week, command)Fields are separated by spaces or tabs:
Minutes: minute field. The value ranges from 0 to 59.
Hours: small time domain. The value ranges from 0 to 23.
Day of month: date. The value ranges from 1 to 31.
Month: month. The value ranges from 1 to 12.
Day of week: day of the week. The value ranges from 0 to 6. The value of Sunday is 0.
Command: the command to be run
If a domain is *, the command can be executed within all possible values of the domain.
If a field is two numbers separated by a hyphen, the command can be executed within the range of two numbers (including the two numbers themselves ).
If a field is composed of a series of values separated by commas, the command can be executed within the range of these values.
If both the date and week fields have values, these two fields are valid.
For example
An Apache access log file is named access_log. Write a shell script to output all the lines in the log containing the IP address 10.3.136.75 to a new file named 75log, and add it to the scheduled task.
Crontab-e
Join
(Every two hours from PM to am, am)
* 11-7/2, 8 *** grep access_log 10.3.136.75> 75log