Qeasy Cloud
Get Started

LinuxCrontab与任务调度配置详解

Source: Qeasy Cloud726 views

集成方案启动后,表头信息无法修改,但表体的平台配置信息仍可更改,并会刷新当前缓存数据。已启动的方案将根据配置的定时策略自动运行。在方案未启动时,队列中的任务不会真正进入队列池。启动方案后,可以在队列池中点击【重新排队】以激活任务。

定时策略配置

Linux crontab 是用来定期执行程序的命令。安装操作系统后,默认便会启动此任务调度命令。crond 命令每分钟检查是否有要执行的工作,如果有则自动执行。注意:新创建的 cron 任务不会马上执行,需要至少2分钟,你也可以重启 cron 来立即执行。Linux 任务调度主要分为以下两类:

  1. 系统执行的工作:如备份系统数据、清理缓存。
  2. 个人执行的工作:例如每隔10分钟检查邮件服务器是否有新信,这些工作由用户自行设置。

crontab 用于让使用者在固定时间或间隔执行程序,相当于使用者的时程表。参数说明如下:

  • -u user: 指定用户的时程表(需要权限,如 root)。
  • e: 使用文本编辑器设定时程表,默认是 VI,可通过设置 VISUAL 环境变量指定其他编辑器(如 setenv VISUAL joe)。
  • r: 删除当前时程表。
  • l: 列出当前时程表。

时间格式如下:f1 f2 f3 f4 f5 program

其中:

  • f1 表示分钟
  • f2 表示小时
  • f3 表示一个月份中的第几日
  • f4 表示月份
  • f5 表示星期几
  • program 表示要执行的程序

具体例子:

  • 当 f1 为 * 时表示每分钟都要执行 program;
  • 当 f1 为 a-b 时表示从第 a 分钟到第 b 分钟内要执行;
  • 当 f1 为 */n 时表示每 n 分钟间隔执行一次; 等等。
* * * * * command to be executed
| | | | |
| | | | +----- 星期几 (0 - 6) (星期天为0)
| | | +------- 月份 (1 - 12)
| | +--------- 一个月中的第几天 (1 - 31)
| +----------- 小时 (0 - 23)
+------------- 分钟 (0 - 59)

常用配置示例参考

Image

Copyright Notice

The article "LinuxCrontab与任务调度配置详解" is original content owned by 广东轻亿云软件科技有限公司. Reposting, quoting, copying or mirroring is strictly prohibited without written authorization. Please contact us for authorization and credit the author and source (including the original link) prominently.