计划任务特性

1. 需要在指定的某时间段运行
2. 需要将任务结果邮件通知用户
3. 单次任务及循环任务区别

Linux计划任务的实现工具

1. at工具
  • 其只能执行一次性任务
  • 其会自动加载部分环境变量
  • 可以执行命令
  • 可以执行脚本
  • 作业有队列,用单字母表示,默认为a队列
  • 作业计划任务是以绝对序列值进行排序
  • 任务结果会以邮件的形式通知用户
2. batch工具
  • 其使用方法与at工具类似
  • 最大的区别为:它会选择系统在比较空闲的时间段执行任务
3. crontab命令
  • 其可以循环执行任务,实现周期性任务
  • 最小时间单位为分钟,如果需要到级别,需要你是用外部机制
  • 可以执行命令
  • 可以执行脚本
  • 每次的任务都会发送邮件至用户通知
  • 其依赖于crond守护进程及相关辅助工具,cronie是其主程序包

一、at工具

synopsis: at [OPTIONS]...time

  • [time]格式

    • HH:MM[YYYY-mm-dd]

      • 20:10 2015-10-30
    • noon : 正午
    • midnight : 午夜
    • teatime : 下午4点
    • tomorrow : 明天
    • now +# UNIT
        * UNIT: min,hours,days,weeks
  • [options]

    • -l : 列出任务队列,相当于atq命令
    • -f FILE : 从指定文件中读取作业任务,不用交互式输入
      • at -f at.sh now+5min
    • -d # : 删除任务
      • at -d 3 ==    atrm 3 :删除第3号任务
    • -c # : 查看指定任务的内容
    • -q a|b|c|d : 指定默认队列

二、crontab工具

cron任务的分类
  • 系统cron任务

    • 配置文件

      • /etc/crontab
    • 配置命令
      • 直接编辑/etc/crontab文件
  • 用户cron任务(root用户也不例外)
    • 配置文件

      • /var/spool/cron/USERNAME
    • 配置命令
      • crontab -e
/etc/crontab文件的格式

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAApMAAAC/CAIAAAAthcDOAAAgAElEQVR4nO2dq7ODvLrG918WE1VVVYVBoaqialBVqCg8qgqFwlScQTFzZiL2IDYKxWyB+E5U5BFcyv3Slha6np9as9rmRsiT983l/df/AgAAAGAP/Pvf//7vf//7LwUAAACAPfDPP//85z//gXIDAAAAu+Gff/6BcgMAAAB7AsoNAAAA7Ak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iKNf2JToLb/qW2zukYqOt9Fayj1W0Qn6i1TMhZ5/LhM9UCmlsrtJCbMso7FZbSJTGVjDnz5vc4/mCeX+JTam3DnCpjW3HDR777QMDCmaW6FaNP3hg4uBai3lTj1GGgIig+tM5U49NrRWPaNIdGBFt1gSrdvj+YJwol5S7rGKTrSR4A3Ha+IxukgbY1fvsaRHKzpBR4Ui50S0W1x9+ORzGe+BRdWZlygVOc39aeOZph4jjUXnTl3G3pdc+Ltb90bz7E0Wyr1TtqjcMrDKYSHxzuTJkRBsh/imkVO+PTcTjnHQtNNjJEp97gRxvqG63A5bKVjqM0p1HrRXwJVSq9ncglNCWC4XWeRdtYfPZ8r9LIWtkcPFjdLlfTb1GSXatTyYlcU+L/eWx+75sSe4aKJiTfUVm3ukolNtFDnVhus0sDSNMX3RFLuQufalACMVnWo9jxFyvaey95cvPJfRHhg5GqmEvX0mbDzTfEebYYfF9vxE3JxSikffF6VUYeiXO97bqQ7lmd1NWswtsshlB8Zgc++WLSp3fgq1OvOCrrV/qlPB+RHdxKu7UmQSOOVi60G7cL95M1vtBGpreXKtHWpVaclBuzhBEjqnmcqt6md0l6/zPKraPlxdP/GuXbgfdx3cT6xzD1d0so1UcrdqB6dTb6lzLAlqzVTrDEMVnUDGd37RiwR7etErz2WgB+ZGq1bzk8iQn0j9GNZ4ps261o+uj74vxVcit1ao2lswlqeMbuxIq5sPMLzuly0qNwAAAACGgHIDAAAAewLKDQAAAOwJKDcAAACwJ6DcAAAAwJ6AcgMAAAB7AsoNAAAA7AkoNwAAALAnoNwAAADAnoByAwAAAHsCyg0AAADsCSg3AAAAsCeg3AAAAMCegHIDAAAAewLKDQAAAOyJf/0fAAAAAPYDlBsAAADYE3OV+38AAAB8hFUHffADQLkBAGBbrDrogx/g/wEuMJKZaYfsiQAAAABJRU5ErkJggg==" alt="" />

每一行定义一个周期性任务
此处的环境变量不同于用户登录后获得的环境,因此,建议命令使用绝对路径,或自定义path环境变量
执行结果邮件发送给想着用户,即mailto=中定义的用户
普通用户不需要定义mailto参数,因为他的任务文件就以用户名命名
共7个字段
如果命令中有%这类的符号,需要转义,但旋转到单引号中的不用转义

crontab命令:

synopsis - crontab [-u user] [-l | -r | -e] [-i] [-s]
[options]
-e : 编辑任务,建议使用crontab -e,这样可以帮忙检查其错误
-l : 列出所有任务
-r : 移除所有任务,即删除对应/var/spool/cron/USERNAME文件
-i : 交互式,在使用-r删除所有用户时,提示用户确认
-u USER : root用户可以为指定的用户管理、指定任务

注意:运行结果会以邮件方式通知当前用户,如果拒绝接收邮件,可以会导致未备份成功却没有任何消息反馈的情况,建设如下操作:

COMMAND > /dev/null : 将正确结果删除,只返回错误输出并发送邮件至用户
COMMAND &> /dev/null : 不建议此操作
指定的某任务在指定的时间因关机未能执行,下次开机不会自动执行
如果某时间点因故未能按时执行,下次开机后无论是否到了相应时间点,都要补充执行一次,可使用anacron实现
每12小时备份一次/etc目录至/backups目录中,保存格式为etc-yyy-mm-dd-hh.tar.xz”
01 */12 * * * root tar Jcf /backups/etc-$(date +"\%F-\%H-\%S").tar.xz /etc/
每周2、4、7备份/var/log/secure文件至/logs目录中,文件名格式为 secure-yyyymmdd
01 09 * * 2,4,7 root tar Jcf /logs/secure-$(date +"\%Y\%m\%d") /var/log/secure
每两个小时取当前系统/proc/meminfo文件中以S或M开头的行信息追加至/tmp/meminfo.txt文件中
01 */2 * * * root grep '^[M\|S]' /proc/meminfo > /tmp/meminfo.txt

Linux之计划任务的更多相关文章

  1. Linux任务计划

    Linux任务计划: 一次性任务执行(at.batch): at:定时任务,指定一个时间执行一个任务,只能执行一次. at使用方式: 交互式:让用户在at>提示符输入多个要执行的命令: 批处理: ...

  2. 配置Linux任务计划

    Linux有三种计划任务: at:指定一个时间执行一个任务 (适用一个或多个任务,执行一次后就不用) cron:根据一个时间表自动执行任务 (使用一个或多个任务,周期性执行) 系统级别的计划任务及其扩 ...

  3. Linux操作系统计划任务

    ++++++++++++++++++++++++++++++++++++++++++++++++标题:Linux操作系统的计划任务内容:计划任务分为单次任务和周期性任务,周期任务分为系统级计划任务和用 ...

  4. Linux中计划任务、周期性任务设置

    Linux中计划任务.周期性任务设置 计划任务:指在未来的特定时间里,执行一次某一特定任务.当然,如果同一任务需要在不同时间点执行执行两次.三次或多次,可以视为多个一次看待. 周期性任务:指某一任务需 ...

  5. Linux定时任务计划

    Linux定时任务计划 在使用Linux系统时,我们有时会需要让系统在某个时间去执行特定的任务,这时就需要去了解Linux提供的定时任务功能 种类 Linux的定时任务分为两种:单一型和循环型 单一型 ...

  6. linux 的计划任务 定时任务

    linux的计划任务,也叫做定时任务 https://www.cnblogs.com/mingforyou/p/3930636.html 名字是crond 查看linux本机的定时任务 crontab ...

  7. linux任务计划 chkconfig工具 systemd管理服务 unit介绍 target介绍

    linux任务计划 任务计划:特定时间备份数据,重启服务,shell脚本,单独的命令等等. 任务计划配置文件:cat /etc/crontab [root@centos7 ~]# cat /etc/c ...

  8. linux任务计划cron

    linux任务计划cron 1.crontab命令任务计划配置文件 [root@bogon ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/ ...

  9. Linux任务计划、周期性任务执行

    Linux任务计划.周期性任务执行 周期性任务执行: cron 守护进程(crond):服务,不间断地运行于后台 # service crond {start|stop|status|restart} ...

  10. linux下计划任务学习记录

    0x01 计划任务简介 linux 中计划任务主要分为”循环执行”和”只执行一次”两种,分别对应的时 crond 服务 和 atd 服务: 0x02 只执行一次的计划任务 0x02.1 atd 服务说 ...

随机推荐

  1. flink Job提交过程

    https://www.jianshu.com/p/0cdfa2a05ebd http://vinoyang.com/2017/04/02/flink-runtime-client-submit-jo ...

  2. angular学习笔记(三十)-指令(8)-scope

    本篇讲解指令的scope属性: scope属性值可以有三种: 一.scope:false 默认值,这种情况下,指令的作用域就是指令元素当前所在的作用域. 二.scope:true 创建一个继承了父作用 ...

  3. 新书《深入应用C++11:代码优化与工程级应用》出版,感谢支持

    经过一年的编写,这本书终于和大家见面了, 已经由机械工业出版社出版,希望本书能给学习C++尤其是C++11的朋友们更多的帮助. 关于C++11 在StackOverflow的最近一次世界性调查中,C+ ...

  4. ES6,新增数据结构Set的用法

    ES6 提供了新的数据结构 Set. 特性 似于数组,但它的一大特性就是所有元素都是唯一的,没有重复. 我们可以利用这一唯一特性进行数组的去重工作. 单一数组的去重. let set6 = new S ...

  5. Android 编程下实现 Activity 的透明效果

    实现方式一(使用系统透明样式) 通过配置 Activity 的样式来实现,在 AndroidManifest.xml 找到要实现透明效果的 Activity,在 Activity 的配置中添加如下的代 ...

  6. 【Android】安卓闪电复习

    Intent An intent is an abstract description of an operation to be performed 一个Intent就是一次对将要执行的操作的抽象描 ...

  7. ES6里新添加了两个很好用的东西,set和Array.from。

    set是一种新的数据结构,它可以接收一个数组或者是类数组对象,自动去重其中的重复项目. 在这我们可以看见,重复的项目已经被去掉了,包括NaN.正常情况下,NaN === NaN 返回的是false,但 ...

  8. Swiper.js的腾讯新闻演示

    演示效果地址:https://www.swiper.com.cn/demo/indexsample/: 代码: <!DOCTYPE html> <html> <head& ...

  9. LeetCode: Add Two Numbers 解题报告

    Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are ...

  10. 获得discuz7.2 目录下所有文件,并写到txt

    # -*- coding: utf-8 -*- import os fileList = [] dzList = [] def GetFileList(path): List = [] for roo ...