cron 可以“缓存”它运行的脚本吗?

cron 可以“缓存”它运行的脚本吗?

先说明一下:1. 我对 *nix 的了解非常有限,但还在不断增长。2. 这个特定问题适用于 SunOS 5.10(我知道),但我对一般答案感兴趣。

如果 cron 条目myscript.pl每分钟运行一次脚本,并且在某个时间点我修改了该脚本文件,那么下一个 cron 执行保证执行改变后的脚本,或者它是否可以在某处/以某种方式拥有一个可以继续执行的缓存版本?

我猜测 Perl 解释器可能也会涉及这个特定的问题。

答案1

它将运行新版本,因为每次 cron 运行时,它都会重复从 crontab 缓存的命令,但不会重复这些命令的“结果”。

因此,如果您更改了脚本,但没有更改实际的 crontab 本身,它每次都会运行新脚本。

如果您更改了 crontab(例如,可能是它的运行频率、脚本的路径等),那么您必须调用crontab它重新读取此信息。否则,cron 将通过 modtime 或使用 ionotify 检查更改,如手册页所示:

   There are two ways how changes in crontables are checked.  The first
   method is checking the modtime of a file.  The second method is using
   the inotify support.  Using of inotify is logged in the /var/log/cron
   log after the daemon is started.  The inotify support checks for
   changes in all crontables and accesses the hard disk only when a
   change is detected.

   When using the modtime option, Cron checks its crontables' modtimes
   every minute to check for any changes and reloads the crontables
   which have changed.  There is no need to restart Cron after some of
   the crontables were modified.  The modtime option is also used when
   inotify can not be initialized.

相关内容