我如何同时使用 nohup 和 time?
How do I use nohup and time together?
我希望能够在 bash shell 而 运行 mpiexec
中同时使用 nohup 和时间,以便输出 (stdout)、错误 (stderr ) 和时间都在 1 个文件中。这是我现在正在使用的:
nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000 > results.log 2>&1"
但是,发生的事情是时间转到名为 nohup.out 的文件,输出和错误转到 results.log
有人解决了吗?
To save output to FILE, use 'nohup COMMAND > FILE'
简单示例:
$ nohup bash -c "time echo 'this is stdout' > results.log 2>&1" >> results.log
nohup: ignoring input and redirecting stderr to stdout
$ cat results.log
this is stdout
real 0m0.001s
user 0m0.000s
sys 0m0.000s
所以,对于你的情况,试试这个:
nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000 > results.log 2>&1" >> results.log
您可以将整个命令括在花括号中以重定向整个输出 { ... ; }
例如:
{ nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000" ; } > results.log 2>&1
Gnu reference :
Bash 提供了两种将要作为一个单元执行的命令列表分组的方法。当命令被分组时,重定向可能会应用于整个命令列表。
(...)
: 创建一个子shell
{...}
: 没有
编辑:
这里不确定是否需要。
我认为问题在于您封闭的“”太宽泛了。
您应该只重定向 nohup
命令的结果,例如:
nohup "foo-cmd -bar argFooBar" > results.log 2>&1
因此,请尝试不包含传递给 bash 的命令的重定向:
nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000" > results.log 2>&1
我希望能够在 bash shell 而 运行 mpiexec
中同时使用 nohup 和时间,以便输出 (stdout)、错误 (stderr ) 和时间都在 1 个文件中。这是我现在正在使用的:
nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000 > results.log 2>&1"
但是,发生的事情是时间转到名为 nohup.out 的文件,输出和错误转到 results.log
有人解决了吗?
To save output to FILE, use 'nohup COMMAND > FILE'
简单示例:
$ nohup bash -c "time echo 'this is stdout' > results.log 2>&1" >> results.log
nohup: ignoring input and redirecting stderr to stdout
$ cat results.log
this is stdout
real 0m0.001s
user 0m0.000s
sys 0m0.000s
所以,对于你的情况,试试这个:
nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000 > results.log 2>&1" >> results.log
您可以将整个命令括在花括号中以重定向整个输出 { ... ; }
例如:
{ nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000" ; } > results.log 2>&1
Gnu reference : Bash 提供了两种将要作为一个单元执行的命令列表分组的方法。当命令被分组时,重定向可能会应用于整个命令列表。
(...)
: 创建一个子shell
{...}
: 没有
编辑:
这里不确定是否需要。
我认为问题在于您封闭的“”太宽泛了。
您应该只重定向 nohup
命令的结果,例如:
nohup "foo-cmd -bar argFooBar" > results.log 2>&1
因此,请尝试不包含传递给 bash 的命令的重定向:
nohup bash -c "time mpiexec.hydra -np 120 -f nodefile ./executable -i 1000" > results.log 2>&1