Linux添加定时任务crond

葛大爷 互联网 2017-10-18 1987
  1. Crontab 介绍

    crontab命令的功能是在一定的时间间隔调度一些命令的执行。

  2. Crontab 的用法 输入内容  输出内容
    #创建或修改crontab文件,文件名为当前用户名,文件在/var/spool/cron/
    crontab -e
    * * * * * /opt/script/test.sh
    * * * * * /opt/script/test2.sh

    #显示所有的crontab任务
    crontab -l
    * * * * * /opt/script/test.sh
    * * * * * /opt/script/test2.sh

    #显示root用户的crontab任务
    crontab -u root -l
    * * * * * /opt/script/test.sh
    * * * * * /opt/script/test2.sh

    #删除crontab文件
    crontab -r
    #删除crontab文件前提醒用户
    crontab -ir
    crontab: really delete root's crontab?
  3. Crond 服务启动停止/span>

    service crond start
    正在启动ser crond: [确定]
    service crond stop
    停止 crond: [确定]
    service crond restart
    停止 crond: [确定]
    正在启动 crond: [确定]
    service crond reload
    重新载入 crond: [确定]

  4. Crond 开机启动设置
    chkconfig --level 35 crond on