1

问题

我正在编写一组脚本来帮助在集群上自动执行批处理作业。我所拥有的具体事物是一个$OUTPUT_DIR,并且是一个任意的$COMMAND
我想执行$COMMAND它的输出以$OUTPUT_DIR. 例如,如果COMMAND='cp ./foo ./bar; mv ./bar ./baz',我想运行它以使最终结果等于cp ./foo ./$OUTPUT_DIR/baz。理想情况下,解决方案看起来像eval PWD="./$OUTPUT_DIR" $COMMAND,但这不起作用。

已知解决方案

[还有他们的问题]

  • 编辑$COMMAND:在大多数情况下,该命令将是一个脚本,或一个编译的 C 或 FORTRAN 可执行文件。改变这些的内部结构不是一种选择。
  • unionfs、aufs 等:虽然这基本上是完美的,但运行它的用户不会有 root,并且导致数千次任意挂载似乎是一个值得商榷的选择。
  • 复制/硬/软链接:这可能是我必须使用的解决方案:实际上将整个内容复制././$OUTPUT_DIR
  • cd $OUTPUT_DIR; ../$COMMAND$COMMAND:读取文件失败
  • 管道:仅在$COMMAND不直接处理文件时才有效;它通常会这样做

是否有我缺少的另一种解决方案,或者这个请求实际上是不可能的?

[编辑:]选择的解决方案

我打算将目录中的每个对象符号链接到输出目录,然后从那里运行命令。这有创建大量符号链接的缺点,但应该不会太糟糕。

4

2 回答 2

2

如果不对$COMMAND. $OUTPUT_DIR“输出最终以”的含义没有单一的定义。对于一个程序,这可能是一些文件,但另一个程序可能只是将某些内容打印到 stdout,而另一个程序可能会尝试使用某种协议通过 Internet 发送一些数据或在 GUI 中显示某些内容,并且没有一种明显的方法来映射所有内容这些到“输出到$OUTPUT_DIR”。

So, you need to invent some assumptions and require any $COMMAND implementation to follow them. Then, it may get as simple as requesting that the command accept a parameter such as --target=<DIR>. If your command was some simple command, you would have to create a wrapper script around it to translate that parameter into what the app accepts. cp, mv and a few more utils already accept the parameter --target, so that may be a good starting point.

于 2012-05-15T08:52:55.317 回答
2

You cannot set the output directory, you can only set the working directory.

The problem is, once you set the working directory, other references are going to be invalid. For example in your code foo:

cp ./foo ./bar

If you have a specific command, there are workarounds (creating a script that alters arguments, prepending the directory to specific arguments), but in general this is not possible.

于 2012-05-15T08:53:30.443 回答