centos 编辑定时任务

安装crontab:
yum install crontabs

说明:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置

查看crontab服务状态:service crond status

手动启动crontab服务:service crond start

查看crontab服务是否已设置为开机启动,执行命令:ntsysv

加入开机自动启动:
chkconfig –level 35 crond on

crontab -u //设定某个用户的cron服务 
crontab -l //列出某个用户cron服务的详细内容 
crontab -r //删除某个用户的cron服务 
crontab -e //编辑某个用户的cron服务 
crontab -i //打印提示,输入yes等确认信息

crontab的配置文件放在 /etc/crontab中
/var/spool/cron/root (以用户命名的文件) 是所有默认存放定时任务的文件
/etc/cron.deny 该文件中所列出用户不允许使用crontab命令
/etc/cron.allow 该文件中所列出用户允许使用crontab命令,且优先级高于/etc/cron.deny
/var/log/cron    该文件存放cron服务的日志

 

00 8,12,16 * * * /data/app/scripts/monitor/df.sh

30 2 * * */data/app/scripts/hotbackup/hot_database_backup.sh

10 8,12,16 * * */data/app/scripts/monitor/check_ind_unusable.sh

10 8,12,16 * * */data/app/scripts/monitor/check_maxfilesize.sh

10 8,12,16 * * */data/app/scripts/monitor/check_objectsize.sh

43 21 * * * 21:43 执行

15 05 * * * 05:15 执行

0 17 * * * 17:00 执行

0 17 * * 1 每周一的 17:00 执行

0,10 17 * * 0,2,3 每周日,周二,周三的 17:00和 17:10 执行

0-10 17 1 * * 毎月1日从 17:00到7:10 毎隔1分钟 执行

0 0 1,15 * 1 毎月1日和 15日和 一日的 0:00 执行

42 4 1 * * 毎月1日的 4:42分 执行

0 21 * * 1-6 周一到周六 21:00 执行

0,10,20,30,40,50 * * * * 每隔10分 执行

*/10 * * * * 每隔10分 执行

* 1 * * * 从1:0到1:59 每隔1分钟 执行

0 1 * * * 1:00 执行

0 */1 * * * 毎时0分 每隔1小时 执行

0 * * * * 毎时0分 每隔1小时 执行
23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart 晚上11点到早上7点之间,每隔一小时重启apache
2 8-20/3 * * * 8:02,11:02,14:02,17:02,20:02 执行 30 5 1,15 * * 1日 和 15日的 5:30 执行
*/1 * * * *  date >>/usr/share/nginx/html/1.txt 
*/1 * * * *  /usr/bin/php  /usr/share/nginx/html/1.php 
*/1 * * * *  echo"demo" >>/usr/share/nginx/html/1.txt 
原文地址:https://www.cnblogs.com/yx520zhao/p/13801249.html