CentOS7定时更新时间

同步时间

1
ntpdate xx.xxx.xx.x

测试用的两个时间服务器地址:

  1. ntpdate 223.65.211.42 — 慢一分钟
  2. ntpdate 202.112.31.197 — 正常

添加cron开机自启动

在/etc/rc.d/rc.local里加入(如果没有执行权限,需要chmod +x rc.local)

1
2
/bin/systemctl start crond.service   或
/bin/systemctl start crond.service (Centos7推荐)

创建定时任务

  1. 执行命令

    1
    crontab -e
  2. 创建定时任务
    vi 命令执行插入
    每小时的15分钟 定时执行更新时间命令

    1
    15 * * * * ntpdate 202.112.31.197
  3. 查看定时任务

    1
    crontab -l
  4. 删除定时任务

    1
    crontab -r

cron相关命令

1
2
3
4
/sbin/service crond start    #启动
/sbin/service crond stop #停止
/sbin/service crond restart #重启
/sbin/service crond reload #重载

crontab的相关命令

1
2
3
crontab  -e  #编辑任务
crontab -l #查看当前用户的任务
crontab -l -u root #查看指定用户的任务

定时任务编写的基本格式

1
2
3
4
5
6
7
8
*  *  *  *  * command
分 时 日 月 周 命令
第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令

本文标题:CentOS7定时更新时间

文章作者:HT

发布时间:2018年03月19日 - 20:03

最后更新:2018年03月19日 - 21:03

原始链接:http://7ht.gitee.io/2018/03/19/CentOS7定时更新时间/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。