ruby - 以编程方式编辑 crontab 并强制守护进程刷新

标签 ruby linux sysadmin cron

我正在尝试使用出色的 CronEdit gem 在 Ruby 中为 Crontab 编写一个 Web 前端。我浏览了 Dillon Cron 的 crontab 源代码,发现它更新了一个特定的文件,以便守护进程在下一次扫描期间刷新 cron 列表。

在 VixieCron 的 man crontab 中,它说:

Additionally, cron checks each minute to see if its spool directory’s modtime (or the modtime on /etc/crontab) has changed, and if it has, cron will then examine the modtime on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.

是否有任何平台(Ubuntu、Red Hat、ArchLinux、Mac OS X)独立的方法来确保在手动编辑 Cron 文件后,守护进程会正确刷新它?

最佳答案

不,没有。如果您知道它是 VixieCron,则更新目录的时间戳。否则,您可能可以伪造它:在调用 crontab -e 之前设置环境变量 EDITOR(这应该为 crontab 调出一个编辑器)。

想法是将编辑器设置为某个进行更改的程序。 crontab -e 将等待编辑器终止并重新读取文件并告诉 cron 某些内容已更改。

但是,如果您有旧版本的 cron,您仍然必须重新启动它。但我怀疑您能否在运行 Linux 或 Mac OS X 的任何设备上找到如此古老的版本。

关于ruby - 以编程方式编辑 crontab 并强制守护进程刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1673143/

相关文章:

ruby-on-rails - Rails - 用一个链接更新多个资源条目

ruby-on-rails - 测试时我应该在 Factory girl 中 stub 模型还是在规范文件中 stub ?

ruby-on-rails - 使用 Rails 自定义验证来修改数据

Linux + uClibc + pthread (C) : application freezes at the end

python - 从 Python 脚本运行时找不到 Nmap

windows - 更改作为镜像安装的 Windows 系统的主机名/IP 地址

css - 使用 css 在 Nokogiri::XML::NodeSet 中设置属性

linux - 如何在 Kali Linux 上从源代码构建 MFOC?

linux alternatives command database(找个名字)

linux - 在远程系统上运行 SSH 脚本 - 退出