Linux之crontab定时任务

Linux之crontab定时任务

一、安装
1.检测系统是否安装crond服务

service crond status

2.开始安装

   yum -y install vixie-cron
   yum -y install crontabs

vixie-cron 软件包是 cron 的主程序;
crontabs 软件包是用来安装、卸装、或列举用来驱动 cron 守护进程的表格的程序。

设置开机自启

chkconfig --level 345 crond on

3.直接输入命令crontab -e 或者编辑文件/etc/crontab 就可以直接设置定时任务。

crontab -e 或者 vi /etc/crontab

二、crontab 常用服务命令

     1、/sbin/service crond start          启动服务

     2、/sbin/service crond stop          关闭服务  

     3、/sbin/service crond restart       重启服务  

     4、/sbin/service crond reload       重新载入配置

     5、/sbin/service crond status       服务是否运行

     6、crontab -l                       列出某个用户的任务计划

实例

30 21 * * * /usr/local/etc/rc.d/lighttpd restart   //每晚的21:30重启apache。

45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart  //每月1、10、22日的4 : 45重启apache。

10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart  //每周六、周日的1 : 10重启apache。

0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart   //每天18 : 00至23 : 00之间每隔30分钟重启apache。

0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart   //每星期六的11 : 00 pm重启apache。

* */1 * * * /usr/local/etc/rc.d/lighttpd restart   //每一小时重启apache

* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart    //晚上11点到早上7点之间,每隔一小时重启apache

0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart    //每月的4号与每周一到周三的11点重启apache

0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart     //一月一号的4点重启apache

*/30 * * * * /usr/sbin/ntpdate 210.72.145.44     //每半小时同步一下时间
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值