Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1548496
  • 博文数量: 157
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4116
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-14 18:26
文章分类

全部博文(157)

文章存档

2014年(67)

2013年(90)

分类: LINUX

2014-08-28 14:03:19


at:    用于执行一次性任务

    at相关的配置文件  /etc/at.allow   /etc/at.deny

    如果存在/etc/at.allow文件,仅允许at.allow中包含的用户使用at;

    如果不存在/etc/at.allow文件,则/etc/allow.deny文件被检查,at.deny文件中不包含的用户都允许使用at;

    如果这两个文件都不存在,则仅允许root使用at;

    缺省情况下,存在一个空的/etc/at.deny,允许所有用户使用at.
    atq = at –l  查询任务队列

    [root@unp ~]# atq
    9       2014-08-29 17:00 a root
    8       2014-08-28 16:00 a root
    [root@unp ~]# at -l
    9       2014-08-29 17:00 a root
    8       2014-08-28 16:00 a root
    atrm = at –d 删除任务

    [root@unp ~]# atrm 8
    [root@unp ~]# atq
    9       2014-08-29 17:00 a root

     
    at 18:00 tomorrow –f file   从文件中读取任务

    [root@unp ~]# at 18:00 tomorrow -f ccdb_rsync.sh
    job 11 at 2014-08-29 18:00
    [root@unp ~]# atq
    9       2014-08-29 17:00 a root
    10      2014-08-29 18:00 a root
    11      2014-08-29 18:00 a root
    at 4pm + 3 days   在3天后的下午4点执行任务

    [root@unp ~]# at 4pm + 3 days
    at> echo "hello"
    at>
    job 15 at 2014-08-31 16:00
    at 10:10 Sep 1  在9月1日的上午10:10分执行任务

    [root@unp ~]# at 10:10 Sep 1
    at> echo "hello"
    at>
    job 16 at 2014-09-01 10:10

 
crontab:      用于执行周期性任务

    crontab相关的配置文件: /var/spool/cron    /etc/cron.allow   /etc/cron.deny

    /var/spool/cron/:用于保存用户的任务的目录

    如果存在/etc/cron.allow文件,则仅允许cron.allow文件中存在的用户使用crontab;

    如果存在/etc/cron.deny文件,则仅拒绝cron.deny文件中存的用户使用crontab;

    如果/etc/cron.allow  /etc/cron.deny都不存在,则只允许root使用crontab.
    crontab –l 显示任务列表
    crontab –e 编辑任务

    [root@unp cron]# crontab -l
    */5 * * * * echo "hello world!"
    0 5 * * * touch file_`date +\%F`.txt

     

    crontab任务的格式

    [root@unp ~]# cat /etc/crontab
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    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

     

    第1个*:分(0-59)

    第2个*:时(0-23)

    第3个*:日(1-31)

    第4个*:月(1-12)

    第5个*: 周(0-6或sun,mon,tue,wed,thu,fri,sat)

    command to be executed:代表执行的命令

    例:

    1.每5分钟执行一次

    */5 * * * *  echo “hello world”

    2.每小时10分,20-30分执行

    10,20-30 * * * *  echo “hello world”

    3.执行秒级的任务,每10秒执行一次

    * * * * * for i in {1..5}; do /bin/echo “how are you?”; sleep; done

    4.如果执行的命令里包含%,需要转义

    0 5 * * * touch file_`date +\%F`.txt

    或者

    0 5 * * * touch file_`date +’%F’`.txt

    anacron   

    anacron也用于执行周期性任务,频率为每小时、每天、每周、每月 分别对应/etc/cron.hourly,/etc/cron.daily,/etc/cron.weekly,/etc/monthly;

    anacron主要用于非24小时开机的系统,通过读取/etc/anacrontab文件来执行任务

阅读(2335) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~