zoukankan      html  css  js  c++  java
  • linux系统中crontab命令、计划任务服务

    1、crontab命令用于创建系统能够周期性、有规律地执行某些具体的任务

    直接测试:crontab -e 进行创建、编辑任务

    [root@linuxprobe test]# ls  ## 查看测试文件
    a.txt
    [root@linuxprobe test]# ll -h
    total 6.6M
    -rw-r--r--. 1 root root 6.6M Oct 19 16:19 a.txt
    [root@linuxprobe test]# crontab -e   ## crontab -e 命令用于创建、编辑计划任务,在终端输入crontab -e命令后直接进入编辑模式,编辑之后进行保存,方法同vim编辑器使用
    crontab: installing new crontab
    [root@linuxprobe test]# crontab -l   ## 列出计划任务服务列表,50表示分,16表示小时,向后的*依次是日、月(缺失的情况下用*表示)、1-7表示星期一到星期日。必须是绝对路径
    50 16 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt
    ## 上句命令的顺序是"分、时、日、月、星期 命令",时间没有设定时,需要用"*"进行站位。 上句命令表示每天的(周一至周日)的16:50对a.txt进行打包压缩 [root@linuxprobe test]# date Mon Oct
    19 16:48:30 CST 2020 [root@linuxprobe test]# crontab -l 50 16 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt [root@linuxprobe test]# date Mon Oct 19 16:49:14 CST 2020 [root@linuxprobe test]# date Mon Oct 19 16:50:39 CST 2020 You have new mail in /var/spool/mail/root [root@linuxprobe test]# ls ## 已经执行计划任务中的打包压缩 a.tar.gz a.txt

    2、cronttab -l 列出计划任务列表  

    [root@linuxprobe test]# ls
    a.txt
    [root@linuxprobe test]# crontab -e
    crontab: installing new crontab
    [root@linuxprobe test]# crontab -l  ## 列出任务
    5 17 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt
    [root@linuxprobe test]# crontab -e
    crontab: installing new crontab
    [root@linuxprobe test]# crontab -l  ## 列出任务
    5 17 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt
    10 17 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt

    3、crontab -r 删除计划任务

    [root@linuxprobe test]# ls
    a.tar.gz  a.txt
    [root@linuxprobe test]# crontab -l
    5 17 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt
    10 17 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt
    [root@linuxprobe test]# crontab -r  ## 删除计划任务服务
    [root@linuxprobe test]# crontab -l
    no crontab for root

    4、在执行多条计划任务时,应每行一条

    [root@linuxprobe test]# ls
    a.txt
    [root@linuxprobe test]# crontab -l
    no crontab for root
    [root@linuxprobe test]# crontab -e
    no crontab for root - using an empty one
    crontab: installing new crontab
    [root@linuxprobe test]# crontab -l  ##列出任务
    10 17 * * 1-7 /usr/bin/tar -czvf /home/test/a.tar.gz /home/test/a.txt
    11 17 * * 1-7 /usr/bin/rm -f /home/test/a.tar.gz
    [root@linuxprobe test]# date
    Mon Oct 19 17:10:01 CST 2020
    [root@linuxprobe test]# ls ## 已执行计划任务1
    a.tar.gz  a.txt
    [root@linuxprobe test]# date
    Mon Oct 19 17:10:07 CST 2020
    [root@linuxprobe test]# date
    Mon Oct 19 17:10:38 CST 2020
    [root@linuxprobe test]# date
    Mon Oct 19 17:11:14 CST 2020
    You have new mail in /var/spool/mail/root
    [root@linuxprobe test]# ls  ## 已执行计划任务2
    a.txt

    注:计划任务中的“分”字段必须有数值,绝对不能为空或者是"*",日和星期不能他同时使用,否则发生冲突

  • 相关阅读:
    汉文博士——支持生僻古难字检索的开放式免费汉语词典
    delphi 实现接口 Unsatisfied forward or external declaration
    注册服务程序
    递归的使用
    NTLDR is missing 错误处理方法
    测试
    常见数据类型的存储结构
    多维分析
    showmodule
    pos函数
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13841364.html
Copyright © 2011-2022 走看看