Welcome 微信登录

首页 / 操作系统 / Linux / Linux下定时任务和例行任务

定时任务
新建一个定时任务
1. at Time     #执行at命令
    #Time的格式有:HH:MM YYYY-MM-DD                                      HH[pm;am] [Month] [Day]
                                      HH[pm;am] + number[hours;days;weeks]
                                      HH:MM
2. 执行此命令后进入指令列下达模式,即输入要执行定时任务的命令,输入完成后按ctrl+D退出,at会输出定时任务编号jobId和执行时间。
可以使用atq查询自己所有的定时任务,使用atrm jobId删除一个定时任务
例行任务
新建一个例行任务
1. crontab -e #进入例行任务编辑模式,使用vi作为编辑器
2. 编写例行任务,如:
    0 12 * * * mail test < /home/test/test.txt
    1,5,6 12 * * * ls /
    * /5 * * * * /home/test/test.sh   #分时日月周 |========指令列===============|使用crontab -l类出自己所有的例行任务,使用crontab -r删除自己所有的例行任务。如要删除某一个任务,使用crontab -e删除对应行就行了。
使用/etc/crontab
我们可以直接编辑/etc/crontab文件来管理例行任务,内容如下
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don"t have to run the `crontab"
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
其中test -x /usr/sbin/anacron,为要执行的命令,run-parts  /etc/cron.daily 表示/etc/cron.daily目录下的可执行文件都要执行一次。 Linux下编译FFmpeg之下载相关解码库并再次编译Linux(Centos)配置OpenSSH无密码登陆相关资讯      Linux基础教程 
  • Linux基础教程:对文件打包压缩  (03月08日)
  • 基础教程:Linux 新手应该知道的   (09/06/2015 21:17:20)
  • Linux基础教程:find 与 xargs  (04/05/2015 10:20:11)
  • Linux基础教程:tar 命令使用介绍  (12/03/2015 13:19:47)
  • Linux基础教程(1)操作系统基础   (08/15/2015 20:44:01)
  • Linux基础教程:从源码安装软件  (04/05/2015 10:14:45)
本文评论 查看全部评论 (0)
表情: 姓名: 字数