Chinaunix

标题: crontab 里的执行顺序 [打印本页]

作者: bandw    时间: 2006-01-24 10:51
标题: crontab 里的执行顺序
怎么让
0 10 * * * cmd1
执行完毕之后再执行cmd2?
作者: laizhou2    时间: 2006-01-24 10:58
cmd1; cmd2 回车
也可以放到后台的,不知道行不行.
作者: 水鬼    时间: 2006-01-24 11:49
0 10 * * * cmd1;cmd2

或者在 cmd1 最后调用 cmd2

呵呵~~
作者: rinehart    时间: 2006-01-24 12:05
好象也可以用 &&
作者: bingosek    时间: 2006-01-24 13:30
“;”“&&”是有区别的
“;”:不管cmd1执行的结果如何,都执行cmd2
“&&”:只有cmd1执行返回的结果是成功的,才执行cmd2
作者: laizhou2    时间: 2006-01-24 14:26
那"||"也可以了...
作者: 水鬼    时间: 2006-01-24 16:40
原帖由 laizhou2 于 2006-1-24 14:26 发表
那"||"也可以了...


cmd1 || cmd2
表示 cmd1 返回结果为假时就执行 cmd2
作者: bandw    时间: 2006-02-06 08:46
如果是cmd1&cmd2;cmd3
是不是cmd1和cmd2都执行完了再执行cmd3?
作者: chinaux    时间: 2006-02-06 10:01
原帖由 bandw 于 2006-2-6 08:46 发表
如果是cmd1&cmd2;cmd3
是不是cmd1和cmd2都执行完了再执行cmd3?



cmd1 && cmd2; cmd3

- cmd1 is executed, if it succeeds, then cmd2. and then cmd3 (regardless of cmd2 success or not)
- cmd1 is executed, if it fails, then cmd3 (cmd2 won't be executed)
作者: chinaux    时间: 2006-02-06 10:04
原帖由 bandw 于 2006-1-24 10:51 发表
怎么让
0 10 * * * cmd1
执行完毕之后再执行cmd2?



if no dependencies:

0 10 * * * cmd1; cmd2


if cmd2 depends on cmd1:
0 10 * * * cmd1 && cmd2
作者: bandw    时间: 2006-02-06 11:02
原帖由 chinaux 于 2006-2-6 10:01 发表



cmd1 && cmd2; cmd3

- cmd1 is executed, if it succeeds, then cmd2. and then cmd3 (regardless of cmd2 success or not)
- cmd1 is executed, if it fails, then cmd3 (cmd2 won't be execu ...



我需要的是cmd1和cmd2都执行完毕(不管cmd1和cmd2的执行结果如何)后再执行cmd3
应该是cmd1 & cmd2; cmd3吧
作者: chinaux    时间: 2006-02-06 11:10
原帖由 bandw 于 2006-2-6 11:02 发表



我需要的是cmd1和cmd2都执行完毕(不管cmd1和cmd2的执行结果如何)后再执行cmd3
应该是cmd1 & cmd2; cmd3吧



it should be:
cmd1; cmd2; cmd3
作者: bigmoyo    时间: 2006-02-06 11:15
标题: cmd1; cmd2; cmd3 为正解
cmd1; cmd2; cmd3 为正解



cmd1 & cmd2; cmd3

一个 & 是"位与"的意思, 可能结果是满足要求的, 从逻辑上讲没有实际意义. 可试试看结果是否满足要求.
即使满足也不建议如此用法.
作者: nu9i    时间: 2006-02-06 12:02
长见识了!藏!
作者: liuziyang    时间: 2006-02-06 14:17
安文件名顺序执行,so your file name can be 1-cron.sh 2-cron.sh ... n
作者: bandw    时间: 2006-02-06 16:30
怎么让cmd1和cmd2同时执行呢?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2