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

    1. 第一次编辑计划任务, 会提示选择文本模式, 选择3 (vim.basic)即可.  (修改编辑模式,输入  select-editor  重新选择)
    2. 语法:  * * * * * command  有几个注意的点: 
      1. * */6 * * * command    表示每天的6:00, 12:00 18:00 24:00 里的每一分钟执行一次, 开始我以为是按照我编辑计划任务的时间算起,  实际不是,   实际是固定的, 系统已经计算好了.
      2. #未完待续...
    3. crontab -u bneglect -l 查看benglect用户的计划任务, crontab  -e 默认编辑当前用户的, crontab -u otheruser -e 编辑otheruser用户的计划任务.
    4. 计划任务脚本所在目录:  /var/spool/cron/crontabs/
    5. 计划任务不执行的原因:  
      1. cron服务是否启动(Ubuntu上是cron, 有的系统是crond) service cron status 或 systemctl status cron 查看服务状态 service cron start 或 systemctl start cron 启动 
      2. shell脚本是否有语法错误, 可以手动执行shell脚本, 如果成功执行, 就是别的原因
      3. shell脚本的路径要写成绝对路径,不能使用相对路径
      4. 创建计划任务的用户没有执行shell脚本的权限, 举例: bneglect创建的计划任务, 但是mysqlBackUp.sh 的属主和属组可能是root(反正不是bneglect), 解决办法: (1)添加bneglect到root属组(2)修改权限为777(3)属主改成bneglect
    6. 编辑脚本保存退出方式: (1) :wq  (2)  crontab编辑文件后保存方式  Ctrl+o, 出现"file name to write.."然后回车, 然后Ctrl+x  显示"crontab: installing new crontab"成功
    7. 在crontab中%是有特殊含义的,表示换行的意思。如果要用的话必须进行转义\%,如经常用的date +%Y%m%d在crontab里是不会执行的,应该换成date +\%Y\%m\%d
    8. date  选项参考:  https://www.cnblogs.com/alsodzy/p/8403870.html
    9. cron 运行的每一项工作都会被纪录到 /var/log/cron 这个登录档中,所以罗,如果你的 Linux 不知道有否被植入木马时,也可以搜寻一下 /var/log/cron
      var/cron
    10. 通过脚本的方式安装crontab: (crontab -l; echo "30 0 * * * /home/Ubuntu/job.sh") | sort -u | crontab - or (crontab -l; echo "30 0 * * * /home/baeldung/job.sh")|awk '!x[$0]++'|crontab - 
      As before, the crontab -l and echo commands write out the previous lines of the crontab as well as the new entry. These are piped through the sort command to remove duplicate lines. The -u option in sort is for keeping only unique lines.
      
      The result of this is piped into the crontab command, which rewrites the crontab file with the new entries.
      
      
      We should be aware, though, that using sort will completely reorder the file, including any comments. sort -u is pretty easy to understand in a script, but we can achieve a less destructive de-duplication with awk:   (This will remove all duplicates from the crontab without sorting it.) 
      
      #!/bin/bash
      (crontab -l; echo "30 0 * * * /home/baeldung/job.sh")|awk '!x[$0]++'|crontab -
      
      
      ref:https://www.baeldung.com/linux/create-crontab-script
      命令解释
  • 相关阅读:
    [转] Spring的session管理
    C# 屏幕截图
    C#数字图像处理图像旋转图片加角度
    C#委托
    C# HttpWebRequest 添加Cookie验证
    网站
    前端获取URL中的值
    从下往上画的文字
    测试SSL的网站
    Tomcat-绑定证书的两种方法
  • 原文地址:https://www.cnblogs.com/bneglect/p/11736694.html
Copyright © 2011-2022 走看看