【发布时间】:2021-06-09 16:42:25
【问题描述】:
我在本地机器上有一个 bash 脚本,它发送一系列命令以在终止之前在 ec2 上运行一些脚本。一段代码如下:
cat ec2-commands.sh
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","aws s3 cp s3://test/scripts/run_model1.sh ."]
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["sudo bash /home/ec2-user/run_model1.sh"]
aws ec2 terminate-instances --instance-ids "${instanceid}"
“run_model1.sh”脚本大约需要 3 小时才能完成。但是,在本地机器上,在终止实例之前无需等待“run_model1.sh”完成。换句话说,本地机器发送命令以运行“run_model1.sh”,并且在 ec2 实例开始运行脚本后,这将被视为“成功”发送命令,并且本地脚本发送命令以终止实例执行后不久.我怎样才能有某种“观看”或“等待”,以便脚本看起来像下面这样:
cat ec2-commands.sh
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","aws s3 cp s3://test/scripts/run_model1.sh ."]
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["sudo bash /home/ec2-user/run_model1.sh"]
[command here to wait for 'run_model1.sh' on the ec2 instance to finish]
aws ec2 terminate-instances --instance-ids "${instanceid}"
或者是否有一个带有 ssm send-command 的选项,它会等到脚本在 ec2 实例上完成?
【问题讨论】:
标签: linux bash amazon-web-services amazon-s3 amazon-ec2