linux CentOS6.3 安装crond定时服务和设置定时任务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux CentOS6.3 安装crond定时服务和设置定时任务相关的知识,希望对你有一定的参考价值。

安装crontab

[[email protected] ~]# yum install vixie-cron

[[email protected] ~]# yum install crontabs

说明:

vixie-cron软件包是cron的主程序;

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

用以下的方法启动、关闭这个cron服务:

/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


1、crond服务管理与访问控制
[[email protected] ~]# service crond restart
[[email protected] ~]# chkconfig crond on

2、用户的crontab设置
[[email protected] ~]# crontab [选项]
选项:
-e: 编辑crontab定时任务
-l: 查询crontab任务
-r: 删除当前用户所有的crontab 任务

[[email protected] ~]# crontab -e
#进入crontab编辑界面。会打开vim编辑你的工作。
* * * * * 执行的任务


第一个“*”
一小时当中的第几分钟
0-59
第二个“*”
一天当中的第几小时
0-23
第三个“*”
一个月当中的第几天
1-31
第四个“*”
一年当中的第几月
1-12
第五个“*”
一周当中的星期几
0-7(0和7都代表星期日)


3.特殊符号含义
*
代表任何时间。比如第一个“*”就代表一小时中每分钟都执行一次的意思。

代表不连续的时间。比如“0 8,12,16 * * * 命令”,就代表在每天的8点0分,12点0分,16点0分都执行一次命令
-
代表连续的时间范围。比如“0 5 * * 1-6命令”,代表在周一到周六的凌晨5点0分执行命令
*/n
代表每隔多久执行一次。比如“*/10 * * * * 命令”,代表每隔10分钟就执行一遍命


4.例子
45 22 * * * 命令
在22点45分执行命令
0 17 * * 1 命令
每周1 的17点0分执行命令
0 5 1,15 * * 命令
每月1号和15号的凌晨5点0分执行命令
40 4 * * 1-5 命令
每周一到周五的凌晨4点40分执行命令
*/10 4 * * * 命令
每天的凌晨4点,每隔10分钟执行一次命令
0 0 1,15 * 1 命令
每月1号和15号,每周1的0点0分都会执行命令。注意:星期几和几号最好不要同时出现,因为他们定义的都是天。非常容易让管理员混乱。


5.举例
*/5 * * * * /bin/echo ”11” >> /tmp/test
5 5 * * 2 /sbin/shutdown -r now
0 5 1,10,15 * * /root/sh/autobak.sh

本文出自 “高山” 博客,谢绝转载!

以上是关于linux CentOS6.3 安装crond定时服务和设置定时任务的主要内容,如果未能解决你的问题,请参考以下文章

Linux crond定时任务

使用linux crond定时请求接口

Linux系统定时任务crond那些事

[Linux之crond计划任务定时任务]

linux定时任务

Linux Centos8上使用系统定时任务crond