美文网首页
linux 定时运行脚本crontab命令

linux 定时运行脚本crontab命令

作者: _花 | 来源:发表于2022-09-02 17:03 被阅读0次

    设置定时执行

    crontab -e
    

    crontab的几个服务命令

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

    基本格式 :

    *****command 分  时  日  月  周  命令

    第1列表示分钟1~59 每分钟用*或者 */1表示

    第2列表示小时1~23(0表示0点)

    第3列表示日期1~31

    第4列表示月份1~12

    第5列标识号星期0~6(0表示星期天)

    第6列要运行的命令

    crontab文件的一些例子:

    #每晚的21:30重启apache。 30 21 * * * /usr/local/etc/rc.d/lighttpd restart
    #每月1、10、22日 45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
    #每天早上6点10分 10 6 * * * date

    image.png

    将服务在系统启动的时候自动启动:

    在/etc/rc.d/rc.local这个脚本的末尾加上:
    /sbin/service crond start

    其他

    比如说root查看自己的cron设置:crontab -u root -l
    再例如,root想删除fred的cron设置:crontab -u fred -r
    在编辑cron服务时,编辑的内容有一些格式和约定,输入:crontab -u root -e

    相关文章

      网友评论

          本文标题:linux 定时运行脚本crontab命令

          本文链接:https://www.haomeiwen.com/subject/ckcynrtx.html