Cron API:有这样的事吗?

jld*_*ont 11 linux cron

有没有像Cron API这样的东西?

我的意思是,是否有一种编程方式来添加/删除Cron作业而不踩到Cron的脚趾?

der*_*ert 8

UNIX cron的API是文件系统.有一个crontab用于安装/编辑用户crontabs 的命令.crontab命令的主要原因是对用户强制执行安全限制(例如,/etc/cron.allow/etc/cron.deny).

系统cron选项卡只是放在/etc/cron.d(和cron.daily/weekly/monthly)中的文件.不需要特别小心; 只需将文件放到位.引用顶部/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.
Run Code Online (Sandbox Code Playgroud)

格式与用户crontabs相同,在crontab(5)中记录,但在命令之前有一个用户字段.其中SPACE表示空格(一个或多个),0和7表示星期日:

分钟 SPACE 小时 SPACE 日期 SPACES SPACE 星期几 SPACE 用户 SPACE 命令

使用普通的POSIX文件访问不会踩到cron的脚趾.请记住,重命名将始终具有指向旧文件或新文件的目标名称,永远不会为空.因此,您可以将文件写入新名称,然后将其重命名为旧文件.

许多编程语言都有API来帮助编写crontabs.例如,CPAN(Perl)有几个.

  • @ Jean-Lou Dupont:正确.您可以将文件放在/etc/cron.d中. (2认同)