crontab
Role: add, search, delete instruction scheduled task.
[root @ localhost ~] # crontab [ options]
Options:
-e: edit crontab scheduled tasks
-l: Query task crontab
-r: delete all the current user's crontab tasks 12345
1
2
3
4
5
|
[root@localhost ~]
# crontab -e
#进入crontab编辑界面。会打开vim编辑你的工作
#输入数据,基本格式为 :
* * * * * command12345
|
1. Format explanation:
For example:
2. Special format
For example
3. Import and Export from the File to file
1
2
3
4
|
#导入
[root@localhost ~]
# crontab filename
#导出
[root@localhost ~]
# crontab -l >filename1234
|
For example:
1, crontab command concept
crontab command instruction set to be executed periodically . The command instructions read from the standard input device, and store it in the "crontab" file for read and executed later.
cron process scheduling system . It can be used to run the job off-peak times of day, or the week run in different time periods or month. cron scheduling process is the main system, you can run the job without the need for manual intervention.
crontab command allows users to submit, edit or delete the corresponding job. Each user can have a crontab file to save the scheduling information. A system administrator can allow or prohibit cron.deny and cron.allow these two documents
Users have their own crontab file.
2 , check whether the installed crontab, if prompted not installed please install yourself, crontab installation package System CD pacekage folder, you can also enter this site to find http://rpmfind.net/ corresponding crontab installation package.
3, crontab service startup and shutdown.
4, the global configuration file:
crontab in the / etc directory exists below cron.hourly, cron.daily, cron.weekly, cron.monthly, cron.d five directories and crontab, cron.deny two files.
cron.daily is performed once a day job
cron.weekly is performed once per week job
cron.monthly it is to perform monthly job
cron.hourly is performed once every hour job
cron.d is automatically on a regular basis to do the task
crontab is set the timer task execution file
cron.deny file is used to specify which users use Crontab function control to prevent
5, user profiles:
Each user has their own cron configuration file can be edited via crontab -e, under normal circumstances we edited the user's cron configuration file save and exit, the system will automatically will be stored in / var / spool / cron / directory, file with your name .linux the cron service once a minute to read all of the content below every /var/spool/cron,/etc/crontab,/etc/cron.d.
6, crontab file format:
* * * * * command
minute hour day month week command
Minutes and days of the week command month
minute: represents minutes, may be any integer from 0 to 59.
hour: the hour, may be any integer from 0 to 23.
day: the date, can be any integer from 1 to 31.
month: the month, can be any integer from 1-12.
week: represents the day of the week, it can be any integer from 0 to 7, where 0 or 7 represents Sunday.
the Command : command to be executed, the system can command, you can also write their own script files.
7, special characters:
An asterisk (*): On behalf of all possible values, such as month if the field is an asterisk, it means that the command is executed operation after a month constraints to meet other fields.
Comma (,): a comma-separated values can be used to specify a list of ranges, e.g., "1,2,5,7,8,9."
The bar (-): can represent an integer in the range of a bar between the integer, e.g., "2-6" indicates "2,3,4,5,6."
Forward slash (/): n frequency intervals can slash specified time, for example, "0-23 / 2" is performed once every two hours. At the same time slash can be used with an asterisk, for example * / 10, if used in minute field representing performed once every ten minutes.
8, in the home directory test.sh write a script, the script function is to copy ifcfg-eth0 this text to the / mnt directory under / home.
9, run crontab -e write a timed task * / 5 * * * * /home/test.sh executed once every 5 minutes test.sh script.
10 , the current user query timed task or delete the current user timed tasks.
11、设置crond开机自动启动。
12、实例: