O:\RHCA\实验总结\20120229_计划任务.docx
计划任务:
1.
系统计划任务:
[root@junjie ~]# vim /etc/crontab
Examples: "1,2,5,9", "0-4,8-12",*,"*/2".
[root@junjie ~]# cd /etc/cron.
cron.d/ cron.deny cron.monthly/
cron.daily/ cron.hourly/ cron.weekly/
系统计划任务实现步骤:
任务(可执行脚本)
à
编辑任务表格(/etc/crontab)
2.
个人计划任务:
crontab
用法:
crontab [-u user] file
crontab [-u user] [-l
查看 | -r删除 | -e编辑] [-i交互] [-s]
3.
调度进程来稍后执行
•
一次性作业使用at,重复性作业使用crontab
•
没有被重导向的输出会被邮寄给用户
•
根用户能够修改其它用户的作业
•
at
时间:MMDDYY or MM/DD/YY or DD.MM.YY HH:MM
•
at 4pm + 3 days at 10am Jul 31 at now +5minutes
4.cron
•
使用时间表完成重复事件
•
使用 crontab 编辑、安装和浏览工作时间表
语法
•
crontab [-u user] file //
为某个用户创建计划任务
•
crontab [-l | -r | -e]
–
-l
列出 crontab
–
-r
删除 crontab
–
-e
使用 $EDITOR 编辑 crontab
cron
访问控制
•
限制 / 允许用户访问 cron (禁止某些用户做计划任务)
–
/etc/cron.allow
(只允许列出的用户使用)
–
/etc/cron.deny
(只拒绝列出的用户使用)
•
包含允许 / 拒绝访问的用户名
•
如果这两个文件都不存在,只有root可用cron
•
如果这两个文件都存在,只有忽略/etc/cron.deny
系统 crontab 文件
•
和用户 crontab 文件的格式不同
•
以下根目录中的主 crontab 文件 /etc/crontab 运行可执行文件
•
时间字段是:分钟、小时、日期、月份、星期
–
/etc/cron.hourly
–
/etc/cron.daily
–
/etc/cron.weekly
–
/etc/cron.monthly
•
/etc/cron.d/
目录包含额外的系统 crontab 文件
日常 Cron 工作
•
tmpwatch
(/etc/cron.daily/tmpwatch)
–
清除指定目录中的旧文件
–
不让 /tmp 目录处于满状态
•
logrotate
–
让日志文件不要变得太大
–
/etc/logrotate.conf
文件的配置自由度高
•
logwatch
(日志情报官)
–
提供系统活动概要
–
报告可疑信息
–
配置文件:/etc/log.d/conf/logwatch.conf
–
/usr/share/logwatch/default.conf/logwatch.conf
anacron
系统
•
anacron
运行计算机关机时cron 不运行的任务
–
假设计算机没有一直开机
–
对笔记本电脑、台式机、工作站及其它不一直开机的系统很重要
–
对偶尔要关机的服务器很有用
•
配置文件:/etc/anacrontab (自动计划任务)
–
字段1:如果在这些日子里没有运行这些任务…
–
字段2:在重新引导后等待这么多分钟后运行它
–
字段3:任务识别器
–
字段4:要执行的任务
本文转自xjzhujunjie 51CTO博客,原文链接:http://blog.51cto.com/xjzhujunjie/792908