查看定时任务格式

[root@centos ~]# vim /etc/crontab

1 SHELL=/bin/bash
2 PATH=/sbin:/bin:/usr/sbin:/usr/bin
3 MAILTO=root
4
5   # For details see man 4 crontabs
6
7   # Example of job definition:
8   # .---------------- minute (0 - 59)
9   # | .------------- hour (0 - 23)
10 # |  | .---------- day of month (1 - 31)
11 # |  | | .------- month (1 - 12) OR jan,feb,mar,apr ...
12 # |  | |  | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
13 # |  | |  | |
14 # * * * * * user-name command to be executed

添加定时任务 (定时更新系统时间)

[root@centos ~]# yum install -y ntpdate

[root@centos ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

手动设置系统时间(测试用)

[root@centos ~]# date -s "2000-1-1"

[root@centos ~]# date

[root@centos ~]# /usr/sbin/ntpdate us.pool.ntp.org

查看当前系统时间

[root@centos ~]# date

设置定时任务,自动执行

[root@centos ~]# mkdir -p /data/crond

[root@centos ~]# crontab -e

添加以下内容 (每1小时就同步一次,并且日志记录到 /data/crond/ntpdate.log)

0 */1 * * * /usr/sbin/ntpdate time.nist.gov 1>>/data/crond/ntpdate.log 2>&1

:wq 保存退出

重启服务

[root@centos ~]# systemctl restart crond

查看服务状态

[root@centos ~]# systemctl status crond

*******************************************

每1分钟执行一次 执行 /data/autorun.sh (必须是有权限,可以执行)
* * * * * /data/autorun.sh

每小时的第3和第15分钟执行
3,15 * * * * /data/autorun.sh

在上午8点到11点的第3和第15分钟执行
3,15 8-11 * * * /data/autorun.sh

每隔两天的上午8点到11点的第3和第15分钟执行:
3,15 8-11 */2 * * /data/autorun.sh

每个星期一的上午8点到11点的第3和第15分钟执行
3,15 8-11 * * 1 /data/autorun.sh

每晚的21:30执行
30 21 * * * /etc/init.d/smb restart

每月1、10、22日的4 : 45执行
45 4 1,10,22 * * /data/autorun.sh

每周六、周日的1 : 10执行
10 1 * * 6,0 /data/autorun.sh

每天18 : 00至23 : 00之间每隔30分钟执行
0,30 18-23 * * * /data/autorun.sh

每星期六的晚上11 : 00 执行
0 23 * * 6 /data/autorun.sh

每一小时执行
* */1 * * * /data/autorun.sh

晚上11点到早上7点之间,每隔一小时执行
* 23-7/1 * * * /data/autorun.sh

每月的4号与每周一到周三的11点执行
0 11 4 * mon-wed /data/autorun.sh

一月一号的4点执行
0 4 1 jan * /data/autorun.sh

每小时执行
01 * * * * /data/autorun.sh

定时任务crontab 例子的更多相关文章

  1. 【转帖】Linux定时任务Crontab命令详解

    Linux定时任务Crontab命令详解 https://www.cnblogs.com/intval/p/5763929.html 知道有crontab 以及 at 命令 改天仔细学习一下 讲sys ...

  2. Linux定时任务Crontab命令详解_转

    转自:Linux定时任务Crontab命令详解 (部分修改) linux 定时系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服 ...

  3. Ntp时间服务器与定时任务Crontab

    一 NTP时间服务器 1 局域网内的NTP同步配置 注意 所有配置操作必须是root用户 ,局域网内node21作为NTP Server,node22,node23作为NTP Client与服务器进行 ...

  4. mysql定时任务简单例子

    mysql定时任务简单例子 ? 1 2 3 4 5 6 7 8 9     如果要每30秒执行以下语句:   [sql] update userinfo set endtime = now() WHE ...

  5. 如何让linux定时任务crontab按秒执行

    如何让linux定时任务crontab按秒执行? linux定时任务crontab最小执行时间单位为分钟如果想以秒为单位执行,应该如何设置呢?思路 正常情况是在crontab中直接定义要执行的任务,现 ...

  6. linux定时任务crontab的设置

    linux定时任务crontab的设置http://www.blogjava.net/freeman1984/archive/2010/09/23/332715.html vi /etc/cronta ...

  7. Linux 定时任务Crontab的使用

    1.准备好Java程序,导出为Jar文件 如myProject.jar 2.写Shell脚本 startTask.sh echo 'start...' cd  /home/root/yourFolde ...

  8. 定时任务Crontab

    0.基本概念 & 实现原理  定时任务基本概念: 调度器:负责管理Quartz应用运行时环境,用于调度定时任务. 定时任务:按照某种时间规则,被调度的任务. a.从有无状态来说,有以下两种: ...

  9. linux 中的定时任务crontab使用方法

    linux 中的定时任务crontab使用方法: 切换到root用户,sudo su root (可以设置成不需要输入密码) sudo su - (需要输入当前帐号的密码才能进入.) crontab ...

随机推荐

  1. jquery简单的轮播效果!

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  2. ubuntu下设置数据库字符集

    就linux环境下出现的数据库乱码的问题,以ubuntu为例进行的总结 ubuntu环境设置的字符集utf8,windows默认字符集是GBK,Ubuntu的默认字符集为utf-8,这使 得在用tel ...

  3. python之Socket网络编程

    什么是网络? 网络是由节点和连线构成,表示诸多对象及其相互联系.在数学上,网络是一种图,一般认为专指加权图.网络除了数学定义外,还有具体的物理含义,即网络是从某种相同类型的实际问题中抽象出来的模型.在 ...

  4. js打印对象数组信息

    function writeObj(obj){ var description = ""; for(var i in obj){ var property=obj[i]; desc ...

  5. js获取url以及截取后边所带参数

    var shopId = ""; function GetRequest() { var url = location.search; //获取url中"?"符 ...

  6. SQL 语句与性能之联合查询和联合分类查询

    select * from t1 left join t2 on t2.sysno =t1.ASysNo left join t3 on t3.sysno =t2.ASysNo left join t ...

  7. js转换数据库中DateTime字段类型

    在程序中,从数据库中读取到的日期时间类型数据一般是这种格式:"/Date(1355109408000+0800)/" 要经过js函数处理变为格式:'2012-12-10 11:05 ...

  8. asp.net dataset 判断是否为空 ?

    1,if(ds == null) 这是判断内存中的数据集是否为空,说明DATASET为空,行和列都不存在!! 2,if(ds.Tables.Count == 0) 这应该是在内存中存在一个DATASE ...

  9. How to configure security of ActiveMQ ?

    Terms {activemq.home}: The ActiveMQ installation folder. How to configure ActiveMQ to use JAAS Authe ...

  10. C# Current thread must be set to single thread apartment (STA) mode before OLE calls can be made

    将箭头指向部分替换为编译器报错的内容即可. 参考文章:https://www.experts-exchange.com/questions/28238490/C-help-needed-Current ...