12.crontab

来源:互联网 发布:开淘宝店做代销赚钱吗 编辑:程序博客网 时间:2024/06/04 18:54

cat /etc/crontab

S
SHELL=/bin/bash
P
PATH=/sbin:/bin:/usr/sbin:/usr/bin
M
MAILTO=root
H
HOME=/

#

For details see man 4 crontabs

#

Example of job definition:

#

.—————- minute (0 - 59)

#

| .————- hour (0 - 23)

#

| | .———- day of month (1 - 31)

#

| | | .——- month (1 - 12) OR jan,feb,mar,apr …

#

| | | | .—- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

#

| | | | |

#

* * * * * user-name command to be executed

/etc/cron.deny 表示不能使用crontab 命令的用户
/etc/cron.allow 表示能使用crontab的用户。
如果两个文件同时存在,那么/etc/cron.allow 优先。
如果两个文件都不存在,那么只有root用户可以安排作业。

crontab命令中的一些常用特殊符号:
符号 
说明
*
表示任何时刻
,
表示分割

表示一个段,如第二段里: 1-5,就表示1到5点
/n
表示每个n的单位执行一次,如第二段里,*/1, 就表示每隔1个小时执行一次命令。也可以写成1-23/1.

0 /1 * *        毎时0分 每隔1小时 执行
2 8-20/3 * * *      8:02,11:02,14:02,17:02,20:02 执行
* * * * * 每分钟执行一次

at(atd): 仅运行一次
crontab(crond): 可循环运行

/etc/init.d/atd restart
chkconfig atd on

at:
1)先搜寻at.allow,只有该文件中存在的用户才可以运行at
2)at.allow不存在,搜寻at.deny,只有该文件中的用户不能使用at
3)两个文件都不存在,只有root能够使用at

at now + 5 minutes
warning: commands will be executed using /bin/sh
at> /bin/mail root -s “testing at job” < /root/.bashrc
at>

at 23:00 2009-03-17
at> /bin/sync
at> /bin/sync
at> /sbin/shutdown -h now

atq
at -c 9
atrm 9

batch executes commands when system load levels permit; in other words, when the load average drops below 0.8, or the value specified in the invocation of atrun

=====================================
crontab:
1)先搜寻cron.allow,只有该文件中存在的用户才可以运行crontab
2)cron.allow不存在,搜寻cron.deny,只有该文件中的用户不能使用crontab
3)两个文件都不存在,只有root能够使用crontab

0 0
原创粉丝点击