Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 使用nohup的一系列命令_Shell_Unix_Nohup - Fatal编程技术网

Shell 使用nohup的一系列命令

Shell 使用nohup的一系列命令,shell,unix,nohup,Shell,Unix,Nohup,我有一系列我想使用nohup的命令 每个命令可能需要一两天的时间,有时我会与终端断开连接 实现这一目标的正确方法是什么 方法1: nohup command1 && command2 && command3 ... 或 方法2: nohup command1 && nohup command2 && nohup command3 ... 或 方法3: 我可以看出方法3可能有效,但它迫使我创建一个临时文件。如果我只能从方法1或2中

我有一系列我想使用nohup的命令

每个命令可能需要一两天的时间,有时我会与终端断开连接

实现这一目标的正确方法是什么

方法1:

nohup command1 && command2 && command3 ...
或 方法2:

nohup command1 && nohup command2 && nohup command3 ...
或 方法3:

我可以看出方法3可能有效,但它迫使我创建一个临时文件。如果我只能从方法1或2中选择,那么正确的方法是什么

nohup command1 && command2 && command3 ...
nohup
仅适用于
command1
。当它完成时(假设没有失败),
command2
将在没有
nohup
的情况下执行,并且容易受到挂断信号的影响

nohup command1 && nohup command2 && nohup command3 ...
我认为这行不通。三个命令中的每一个都将受到
nohup
的保护,但处理
&&
运算符的shell将不受保护。如果您在
command2
开始之前注销,我认为它不会启动;同样,对于
命令3

echo -e "command1\ncommand2\n..." > commands_to_run
nohup sh commands_to_run
我认为这应该行得通——但还有一种方法不需要创建脚本:

nohup sh -c 'command1 && command2 && command3'
然后保护外壳不受挂断信号的影响,我相信这三个子命令也是如此。如果最后一点我错了,你可以:

nohup sh -c 'nohup command1 && nohup command2 && nohup command3'
我认为(但不知道)答案是“要么”。但这两种方法都不允许您重新连接以查看进程的任何输出。如果您想做到这一点,您需要研究GNU屏幕或tmux之类的东西。
nohup sh -c 'nohup command1 && nohup command2 && nohup command3'