2

有没有办法告诉 cron 如果同时有更高优先级的作业,它应该只执行更高优先级的作业?

例如:

0 12 * * * ~/ring_a_bell.sh # mplayer bell.wav

将是标准振铃。但是只有一次,例如在我生日那天,我不想让它响铃_a_bell.sh,而是玩_a_birthday_mellody.sh:

0 12 21 3 * ~/play_a_birthday_mellody.sh # mplayer birthday.wav
0 12 * * * ~/ring_a_bell.sh # mplayer bell.wav

我读到 at-job 可以做这种工作,但问题是两者都会cron同时at执行这项工作。这听起来不太好。有没有办法告诉 cron 检查哪个优先级更高并且只执行其中一个?

4

1 回答 1

2

据我所知,cron 并不那么聪明。我可以想到一种在 cron 中编写逻辑代码的简单方法,但这并不是那么好。

59 11 21 3 * ln -s ~/play_a_birthday_mellody.sh ~/script_which_plays_stuff.sh
5  12 21 3 * ln -s ~/ring_a_bell.sh ~/script_which_plays_stuff.sh
0  12 * * * ~/script_which_plays_stuff.sh

并作为一次性设置,创建~/script_which_plays_stuff.sh为符号链接~/ring_a_bell.sh

无论如何,使用 cron 的传统方式是运行另一个脚本,您可以在其中编写逻辑代码。

于 2013-03-21T18:49:28.210 回答