zoukankan      html  css  js  c++  java
  • Linux 任务计划:crontab

    (1) 什么是任务计划:也就是设置服务器在某个指定的时间执行某个指定的任务,比如执行一个命令,或执行一个脚本
    (2) Linux 使用 cron 服务来制定任务计划,cron 是服务名称,crond 是后台进程,crontab 是定制好的计划任务表
    (3) cron 有两个配置文件,一个是全局配置文件(/etc/crontab),是针对系统任务的;一个是 crontab 命令生成的配置文件(/var/spool/cron/username),是针对某个用户的定时任务

    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # |  |  |  |  |
    # *  *  *  *  * user-name  command to be executed   --- 使用哪个用户来执行命令
    [root@localhost ~]$ crontab -e              # 编辑当前用户的任务计划表
    [root@localhost ~]$ crontab -l              # 查看当前用户的任务计划表
    [root@localhost ~]$ crontab -r              # 清空当前用户的任务计划表
    [root@localhost ~]$ crontab -u <user> -e    # 编辑指定用户的任务计划表
    [root@localhost ~]$ crontab -u <user> -l    # 查看指定用户的任务计划表
    [root@localhost ~]$ crontab -u <user> -r    # 清空指定用户的任务计划表
    [root@localhost ~]$ systemctl start crond.service    # 启动任务计划
    [root@localhost ~]$ systemctl stop crond.service     # 停止任务计划
    [root@localhost ~]$ systemctl status crond.service   # 查看启动状态
    * * * * * command          # 每分钟执行一次
    0 3 * * * command          # 每天凌晨3点执行一次
    0 3 1 * * command          # 每个月1号的凌晨3点执行一次
    0 3 1-10 * * command       # 每个月的1-10号的凌晨3点执行一次
    0 3 1,10,20 * * command    # 每个月的1号/10号/20号的凌晨3点执行一次
    */2 * * * command          # 每两分钟执行一次,也就是能被2整除的分钟(2,4,6,8,....)
    * * * */2 * command        # 每两个月执行一次,也就是能被2整除的月份(2,4,6,8,10,12)

        

  • 相关阅读:
    new一个对象的时候,实际做了些什么
    ES6 class——getter setter音乐播放器
    vue中引入公用过滤器?
    this详解下
    012天this详解上
    011天之跨域资源共享CORS
    010天JSON.stringify()详解
    009天之跨浏览器的事件处理程序
    使用XHR上传文件要不要了解一下?
    简单化最小化语句数
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10312487.html
Copyright © 2011-2022 走看看