首页 技术 正文
技术 2022年11月7日
0 收藏 398 点赞 1,084 浏览 1653 个字

(1) at 一次性的计划任务

语法:

# at [参数] [时间]

at> 执行的指令

退出at命令 ctrl+d

[root@localhost ~]# at now
at> mkdir te
at> cp /etc/passwd /te
at> <EOT>

[root@localhost ~]# atq   查询at任务

[root@localhost ~]# atrm  删除at任务

at会把任务放到/var/spool/at目录下。

(2) crontab 周期性的计划任务

语法格式:

[root@localhost ~]# vim /etc/crontab
# Example of job definition:
# .---------------- minute ( - )
# | .------------- hour ( - )
# | | .---------- day of month ( - )
# | | | .------- month ( - ) OR jan,feb,mar,apr ...
# | | | | .---- day of week ( - ) (Sunday= or ) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed[root@localhost ~]# crontab -e -u username #为username创建任务
[root@localhost ~]# crontab -l -u username #列出任务
[root@localhost ~]# crontab -r -u username #删除任务* * * * * /bin/echo hello
*/ * * * * /bin/echo hello #每隔一分钟

(3) anacron

也是Linux系统中的调度工具,与cron很类似(可每天、每周或每月周期性地执行),但也有不同:

– 执行cron的系统必须随时保持启动,因为如果在指定的时间主机没有正常启动,则调度的任务就无法执行。

– anacron如果在指定的时间没有成功执行,则会在一段时间进程控制与管理之后再次执行,所以顺利执行的概率较高。

所有的任务都设置在/etc/anacrontab文件中,在这个文件中的每一行都表示一个任务(注释与环境变量例外),它们的格式如下:

时间间隔    等待时间   任务标识   命令

• 时间间隔:执行任务的时间间隔,单位为天。

• 等待时间:在时间间隔到期后,如果任务没有顺利执行,则会等待此处设置的时间,然后再次尝试执行。

• 任务标识:有关此任务的说明,它可包含任何非空格的字符(/除外),通常都用在anacron信息中,或是此任务的时间戳文件名。

• 命令:实际执行的任务。

当任务完成后,anacron会将此日期记录在/var/spool/anacron目录的Timestamp文件中,默认的Timestamp文件有三个:cron.daily,cron.monthly和cron.weekly

[root@localhost ~]# vim /etc/anacrontab
# /etc/anacrontab: configuration file for anacron# See anacron() and anacrontab() for details.SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=
# the jobs will be started during the following hours only
START_HOURS_RANGE=-#period in days delay in minutes job-identifier command
cron.daily nice run-parts /etc/cron.daily
cron.weekly nice run-parts /etc/cron.weekly
@monthly cron.monthly nice run-parts /etc/cron.monthly
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,411
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,184
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,904