RHCE7 管理II-4计划将来的Linux任务
2024-08-24 14:48:39
(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
最新文章
- [教学] Delphi Berlin 10.1 开发 Windows 10 平板 App 远程调试
- Windbg使用简明指南
- 转mysql 多表 update sql语句总结
- 一点一滴学shell-Shell expr的用法 (转)
- How to use liftover
- UVA 11889 Benefit
- 在C语言中以编程的方式获取函数名
- Jdk1.6 JUC源码解析(12)-ArrayBlockingQueue
- Zigbee Class 直播公告2016-10-10
- vector动态数组
- 时序图中的生命线与类绑定(EA)
- Oracle使用学习笔记(一)
- 怎样用git上传代码到github以及如何更新代码
- Eclipse中java文件生成jar文件的方法
- beta版验收互评
- Django-wed开发框架-练习题
- 集成Glide4.3.1出错!AbstractMethodError: abstract method ";void com.bumptech.glide.module
- MYSQL performance
- 0.0 配置JAVA环境和Maven环境(W10注意点)
- USB设备被识别流程【转】