多个nohup同时跑报错
时间: 2023-09-07 10:01:53 浏览: 45
当多个`nohup`命令同时运行时,可能会出现报错的情况。这是因为`nohup`命令在后台运行时,会将标准输出重定向到一个名为`nohup.out`的文件中,而同时运行多个`nohup`命令时,可能会导致多个命令同时向同一个文件写入输出内容,从而引发冲突和报错。
要解决这个问题,可以采取以下几种方法:
1. 使用不同的输出文件:可以通过在每个`nohup`命令后面添加不同的输出文件路径,来避免多个命令同时向同一个文件写入内容,例如:
```
nohup command1 > output1.txt &
nohup command2 > output2.txt &
```
2. 使用管道重定向:如果不需要将命令的输出保存到文件中,可以使用管道将每个命令的输出传递给其他命令,避免冲突,例如:
```
nohup command1 | some_other_command &
nohup command2 | another_command &
```
3. 串行执行命令:如果需要保证多个命令的输出按顺序执行,可以使用分号将多个命令串联起来,让它们按顺序执行,例如:
```
nohup command1 ; nohup command2 ;
```
需要注意的是,以上方法可能需要根据具体情况进行调整,以适应不同的应用场景和需求。
相关问题
脚本执行nohup报错
回答: 当脚本执行nohup报错时,可能有几个原因导致。首先,可能是脚本中的命令无法调用或执行。这可能是由于权限问题或命令不存在导致的。其次,可能是nohup命令的输出重定向到的文件不可写,导致无法将输出写入文件中。最后,可能是脚本中的命令执行出错,导致nohup命令无法成功执行。请检查脚本中的命令是否正确,并确保输出重定向的文件可写。如果问题仍然存在,建议查看脚本执行过程中的日志文件,以便更好地定位问题所在。\[2\]\[3\]
#### 引用[.reference_title]
- *1* *2* [jenkins使用shell脚本执行nohup java -jar包失败](https://blog.csdn.net/joshua317/article/details/125871391)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [nohup](https://blog.csdn.net/u010608296/article/details/112338473)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
linux nohup 多个命令
使用Linux的nohup命令可以使某个命令在后台运行,并且即使退出终端,该命令也能继续运行。如果要在nohup中运行多个命令,可以使用分号或者&&符号将多个命令连接在一起。
使用分号的方式如下:
nohup command1 ; command2 ; command3 &
使用&&符号的方式如下:
nohup command1 && command2 && command3 &
这两种方式的区别在于,使用分号的方式,即使前面的命令执行失败也会执行后面的命令;而使用&&符号的方式,只有前面的命令执行成功后才会执行后面的命令。
例如,如果要在后台运行两个命令:打印当前目录下的文件列表并保存到文件中,再将该文件复制到另外一个目录中,可以使用以下命令:
nohup ls -al > filelist.txt ; cp filelist.txt /tmp/ &
或者使用以下命令:
nohup ls -al > filelist.txt && cp filelist.txt /tmp/ &
无论使用哪种方式,多个命令的执行顺序与连接符号的顺序有关,需要根据实际情况选择合适的方式。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)