该标准cron缺乏第二次精确调度,因为
但是,在sleep(1)GNU Coreutils套件的帮助下,您可以实现真正的第二精度作业调度.
示例:等待12:14:05和12:14:10
$ crontab -l
(snip...)
14 12 * * * sleep 5; date > /tmp/plain.txt
14 12 * * * while [ "1410" -gt "$(date +\%M\%S)" ]; do /bin/sleep 0.1; done; date > /tmp/while.txt
Run Code Online (Sandbox Code Playgroud)
(稍等片刻...)
$ ls -l --time-style=full-iso /tmp/*.txt
-rw-r--r-- 1 nodakai nodakai 43 2014-02-22 12:14:06.236151567 +0800 /tmp/plain.txt
-rw-r--r-- 1 nodakai nodakai 43 2014-02-22 12:14:10.007600677 +0800 /tmp/while.txt
Run Code Online (Sandbox Code Playgroud)
当你从第1版看到,14 12在crontab不保证12:14:00锐利.第二个版本使用whileloop和sub-second sleep(1)来实现亚秒级精度.
请注意,除非您使用NTP将计算机时钟与时间服务器同步,否则谈论第二次精确作业调度毫无意义.
| 归档时间: |
|
| 查看次数: |
2896 次 |
| 最近记录: |