Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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
Linux 在远程计算机上严格按顺序执行bash命令_Linux_Bash - Fatal编程技术网

Linux 在远程计算机上严格按顺序执行bash命令

Linux 在远程计算机上严格按顺序执行bash命令,linux,bash,Linux,Bash,我需要确保在远程机器上严格地一个接一个地运行命令。实现这一目标的最佳方法是什么?任何后续命令都必须等待上一个命令完成。这是我正在使用的.sh脚本,到目前为止(尽管我不确定),它看起来就像是同时执行命令 ssh root@some_host << 'EOF' docker pull author/image:latest docker stop currently_running_container docker rm currently_runnning_conta

我需要确保在远程机器上严格地一个接一个地运行命令。实现这一目标的最佳方法是什么?任何后续命令都必须等待上一个命令完成。这是我正在使用的
.sh
脚本,到目前为止(尽管我不确定),它看起来就像是同时执行命令

ssh root@some_host << 'EOF'
   docker pull author/image:latest
   docker stop currently_running_container
   docker rm currently_runnning_container
   # etc
EOF

sshroot@some_host除非您在后台以
&
结尾运行它们,否则命令是按顺序执行的。您的意思可能是,当任何命令失败时停止脚本?您可以通过
&&
实现这一点。例如:
docker pull author/image:latest&&docker stop current_running_container&&docker rm current_running_container
@Barmar ok,明白了,如果它们是按顺序执行的,那么这就是我需要的@RandallFlagg说得好,谢谢你的提示!现在,我可能会在每一行的末尾添加`&&\`,这与以前基本相同,只是如果任何命令失败,脚本现在将停止。