Linux学习笔记重新梳理20180704 之 定时任务crontab

crontab 是一个用于设置周期性被执行的任务的工具


安装

yum install vixie-cron
yum install crontabs


启动

service crond start


检查任务列表

crontab -l


编辑任务

crontab -e
说明:和vi操作类似

案例
crontab -e
*/1 * * * * date >> /tmp/log.txt

tail -10f /tmp/log.txt


基本组成

crond   系统服务    从配置文件中刷新定时任务
常用操作:
service crond start
service crond stop
service crond status

配置文件    配置定时任务
如:/etc/crontab
/etc/cront.d/*
/etc/cront.d/sysstat


# 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

crontab 配置工具    调整定时任务

日志
/var/log/cron*


定时任务案例

每天2:30重启apache
30 2 * * * service httpd restart

每个月的1号10号20号的1:30
30 1 1,10,20 * * service httpd restart

每个月的1号到10号的1:30
30 1 1-10 * * service httpd restart

每个月的1号到10号和20号到23号的1:30
30 1 1-10,20-23 * * service httpd restart

每隔2分钟
*/2 * * * * service httpd restart
1-59/2 * * * * service httpd restart
(0、2、4、6···)
(1、3、5、7···)

晚上23点到7点之间每隔1小时
0 23-7/1 * * * service httpd restart

每天18点到23点每隔30分钟
0,30 18-23 * * * service httpd restart
0-59/30 18-23 * * * service httpd restart

总结:
*   任意时间
A,B,C   A 或  B或 C
A-B     A 到 B
*/A     每隔A时间

转载于:https://my.oschina.net/mengzhang6/blog/1839925

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值