• 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)

        

  • 相关阅读:
    设计模式
    设计模式
    设计模式
    设计模式
    【Sublime】许可证 及 相关设置
    【Linux】跳过ubuntu grub2引导,使用Windows引导ubuntu
    【Linux】Windows 7下硬盘安装Ubuntu 14.10图文教程
    【ACM】连连看 hdu1175
    【算法】约瑟夫环 C++源代码
    【Java】配置JAVA的环境变量
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10312487.html
Copyright © 2020-2023  润新知