0

我有一个 crontab,我在其中发出两个命令,我想在两个命令之间添加一个时间睡眠,如下所示:(command1 ; sleep ; command2)。

这可能吗?它是如何格式化的?

请帮忙!!

4

2 回答 2

0

任何连续的有效shell命令都可以。保持在一条线上。

于 2012-09-06T17:27:28.220 回答
0

The ``sixth'' field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. - the crontab(5) man page

Essentially you already have the right base form, like: cmd1 ; sleep 60 ; cmd2 Any command, even complicated commands with loops and other logic should work, although you should be careful about which environment variables you might be relying on.

It's useful to run job in the near future to email the output of "env" to yourself just to check ;-)

For more complex stuff, create a shell script and have the crontab refer to it, like:

42 0 * * * $HOME/bin/daemon/cron-tmp-preen

于 2012-09-06T17:09:06.433 回答