我写了一个bash脚本来最后构建一个docker容器(一个NODE JS应用程序),以便该应用程序在DEV服务器上运行。问题是bash脚本必须在多个服务器上分阶段运行,即,我们需要在本地构建docker容器,将ssh到跳转框并在其中进行rsync,然后将其从Jumpbox同步到dev服务器,然后再次使用它(如果手动完成此过程)。
如果您在下面的BASH脚本中查看第5步,则rsync会完成,并且脚本会运行到SSH到Jumpbox服务器,但是,脚本在那里停止了,我刚刚登录到Jumpbox。
有人可以让我知道此bash脚本出了什么问题,我该如何解决?
谢谢。
最好, R
#!/bin/bash
#This script allows users to deploy the application with minimal work
echo -n "Shall we begin the deployment process? Are you ready to rule the world with QA Hero's next version? `\n` If you are, then type YES and press [ENTER]?: "
read begin
echo "Wohoooo! You did the right thing! We are now ready to roll and you can actually see your terminal scroll! Lol, what a troll!"
echo -n "Yo mate! Can you enter your enumber and press [ENTER]?: "
read enumber
docker build --build-arg NODE_ENV=staging -t course-hero-x -f Dockerfile .
echo "The file has been built! Step 1 completed"
termdown 3
echo "BOOM! Get ready for step 2."
docker save -o course-hero.tar course-hero-x
termdown 3
echo "BOOM! Get ready for step 3."
rsync -avzh --progress --stats course-hero.tar `echo ${enumber}`@10.188.129.25:/home/`echo ${enumber}`
termdown 3
echo "BOOM! Get ready for step 4."
ssh `echo ${enumber}`@10.188.129.25
termdown 3
echo "BOOM! Get ready for step 5."
ls -la
termdown 3
echo "BOOM! Get ready for step 6."
if ["$enumber" == "e30157" || "$enumber" == "E30167"]; then
rsync -avzh --progress --stats course-hero.tar `echo ${enumber^^}`@10.80.63.65:/home/eh7/`echo ${enumber^^}`
elif ["$enumber" == "e32398" || "$enumber" == "E32398"]; then
rsync -avzh --progress --stats course-hero.tar `echo ${enumber^^}`@10.80.63.65:/home/eh8/`echo ${enumber^^}`
else
echo "You cannot access this system."
fi
termdown 3
echo "BOOM! Get ready for step 7."
ssh `echo ${enumber^^}`@10.80.63.65
echo "BOOM! Get ready for step 8."
ls -la
echo "BOOM! Get ready for step 9."
sudo docker load -i course-hero.tar
termdown 3
echo "BOOM! Get ready for step 10."
sudo docker ps
termdown 3
echo "BOOM! Get ready for step 11."
sudo docker stop $(sudo docker ps -a -q)
termdown 3
echo "BOOM! Get ready for step 12."
sudo docker rm $(sudo docker ps -a -q)
termdown 3
echo "BOOM! Get ready for step 13."
sudo docker load -i course-hero.tar
termdown 3
echo "BOOM! Get ready for step 14."
sudo docker run -d -e TZ=Australia/Melbourne --net=courseHero -p 0.0.0.0:80:3000 course-hero-x
echo "QA Hero is up and running. Go to http://cohero-dev.rmit.edu.au to checkout the latest version!"
termdown 3
echo "Step 15 completed! We are done here! See you next time homey!"
答案 0 :(得分:1)
一旦您向另一个框打开ssh会话,您的本地脚本就会停止,因为它正在等待ssh会话结束。您只是坐在远程框中的命令提示符下。
看起来您打算发生的是ssh之后的命令在远程机器上运行。要将命令发送到远程计算机,请重定向它们:
ssh ${enumber}@10.188.129.25 <<'ENDSSH'
# series of commands to
# run on remote host
ENDSSH
考虑通过Shellcheck运行脚本-除了您要的脚本之外,您还有其他问题。