您的位置:首页 > 运维架构 > Linux

Linux定时任务 - atd和crond

2013-02-14 20:45 281 查看
d在结尾处一般表示服务

crond一般用的比较多

打开/etc 找到cron开头的文件和文件夹

root@iwissen:/etc# ls -ld cron*
drwxr-xr-x 2 root root 4096 Feb  7 18:03 cron.d
drwxr-xr-x 2 root root 4096 Aug 21 23:58 cron.daily
drwxr-xr-x 2 root root 4096 Aug 21 23:56 cron.hourly
drwxr-xr-x 2 root root 4096 Aug 21 23:56 cron.monthly
drwxr-xr-x 2 root root 4096 Aug 21 23:58 cron.weekly
-rw-r--r-- 1 root root  718 Feb  7 18:03 crontab
打开cron.daily文件夹,看看里面有什么

root@iwissen:/etc# cd cron.daily/
root@iwissen:/etc/cron.daily# ll
total 16
drwxr-xr-x  2 root root 4096 Aug 21 23:58 ./
drwxr-xr-x 84 root root 4096 Feb  9 05:56 ../
-rwxr-xr-x  1 root root  372 Oct  5  2011 logrotate*
-rwxr-xr-x  1 root root 1309 Oct 26  2010 sysklogd*
很多都是脚本

这些脚本每天都执行

hourly每小时执行,monthly每月,weekly每周

通过这种方式创建周期性执行脚本

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
43 * * * * root cd / && run-parts --report /etc/cron.hourly
3 5 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
29 5 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
20 3 7 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )


* * * * * 表示

分时日月周

crontab -e 创建定时任务
例如,每分钟执行一个命令

* * * * * "this will run every minute"

crontab -l 查看当前用户定时任务

详情请见man
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: