Chinaunix首页 | 论坛 | 博客
  • 博客访问: 60467
  • 博文数量: 38
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 396
  • 用 户 组: 普通用户
  • 注册时间: 2015-07-12 14:46
文章分类

全部博文(38)

文章存档

2016年(11)

2015年(27)

我的朋友
最近访客

分类: 系统运维

2015-08-28 23:02:48

周期性计划任务:

配置文件:

 vim /etc/crontab

*     *      *     *     *

               

 

/etc/init.d/crond status     

crond (pid  2199) is running...

[root@xuegod163 ~]# chkconfig --list crond           #查看是否开机启

crond              0:off       1:off       2:on 3:on 4:on 5:on 6:off

[root@xuegod163 ~]# chkconfig crond on            #配置开机自启动

 

对于系统级别的计划任务,需要执行的命令和脚本都放在这里:

[root@xuegod163 ~]# ls /etc/cron.*

/etc/cron.hourly   /etc/cron.daily   /etc/cron.weekly    /etc/cron.monthly

 

针对用户级别的计划任务:

对于root用户:

命令:

#crontab –e   创建一个计划任务 

#crontab –l    显示

#crontab –r   删除计划任务

#crontab –e   #写法

分 时 日 月 星 谁做后面的事情 命令

 

每个取值范围:

分:059

小时:023

日:131

月:112

周:07   0 7 都是周日

 

例:

crontab -e

58 20 * * *  echo `date` > /root/date.txt

 cat date.txt

Mon Jul 20 20:58:01 CST 2015

 

查看计划任务

 crontab -l

58 20 * * *  echo `date` > /root/date.txt

 

特殊写法:

#9,18,22这几天的3点,开始执行备份脚本

 

crontab -e

0     3   9,18,22    *    *   /root/backup.sh

 

#每月9-18日,这几天,3:00执行

0     3     9-18        *    *   /root/backup.sh

 

#5分钟,执行一次

*/5  *    *      *     *      /root/backup.sh

 

例:

1 1 * * * find /home/log -type f -a -mtime +5  -exec rm {}  \;




阅读(511) | 评论(0) | 转发(0) |
0

上一篇:本地yum源配置

下一篇:linux时间戳

给主人留下些什么吧!~~