• linux 计划任务 crontab 简单用法


    添加计划任务:

    方法1:
    crontab -e
    
    方法2:
    vim /etc/crontab  #这种方式进去的文件有个sample可供参考
    查看已经启动的任务:
    crontab -l

    查看运行状态:
    service crond status
    /sbin/service crond start
    /sbin/service crond stop
    /sbin/service crond restart
    /sbin/service crond reload
    以上1-4行分别为启动、停止、重启服务和重新加载配置。
    
    要把cron设为在开机的时候自动启动,在 /etc/rc.d/rc.local 脚本中加入 /sbin/service crond start 即可
    
    查看当前用户的crontab,输入 crontab -l;
    
    编辑crontab,输入 crontab -e;
    
    删除crontab,输入 crontab -r

    查看cron的log日志文件:

    tailf /var/log/cron

    重启crond服务:

    service crond restart
    参考:https://www.cnblogs.com/cuisi/p/6251848.html

    【crontab的环境变量问题】
    1.脚本中:直接使用mysql命令 命令:手动执行脚本,正常输出文件。因为:/etc/profile 中加入 了系统环境变量:/usr/local/mysql/bin/ 2.crontab执行:如果想成功执行 分两种情况: 1.脚本中mysql命令指定绝对路径:/usr/local/mysql/bin/mysql 2.将mysql可执行文件复制到:crontab的环境变量指定的路径中 ------------------------------------------------------ # crontab的配置文件!!!

    ------------------------------------------------------
    [root@monitor2 scripts]# cat /etc/crontab
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin # 将mysql可执行文件复制到/usr/bin下,脚本中就可以直接使用mysql命令
    MAILTO=root
    HOME=/

    # For details see man 4 crontabs

    # 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
    -------------------------------------------------------------

  • 相关阅读:
    LeetCode 116. 填充每个节点的下一个右侧节点指针
    angluar 表单的验证 动态数据项表单验证
    Angular:ng-style,ng-class的使用
    1.splice(),slice(),split()快查
    js输入小写金额转大写
    Angular--CheckBox,checkbox多选,保存的时候用逗号隔开
    Angular--CheckBox
    Angular--Radio
    对于mysql中的group by分组后获取组内创建时间最大的那行数据
    GIT版本管理看这一篇就够了
  • 原文地址:https://www.cnblogs.com/gavinyyb/p/9176936.html
Copyright © 2020-2023  润新知