EC2 JSON模板bash脚本不执行这一切 [英] EC2 json template bash script not executing all of it

查看:172
本文介绍了EC2 JSON模板bash脚本不执行这一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这部分我的模板:

            "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
              "sudo yum update -y\n",
              "sleep 30\n",
              "sudo mkdir /data \n",
              "cd /data/\n"
                  ]]}}

有服务器。看来要执行的第一行(因为我可以使用wget),但不这样做的第三或第四线。有什么想法吗?谢谢!

for the server. It seems to execute the first line (since I can use wget) but doesn't do the 3rd or 4th lines. Any thoughts? Thanks!

推荐答案

用户数据不作为脚本运行,除非前两个字符是#!

The user-data is not run as a script unless the first two characters are #!

尝试加入以下作为用户数据的第一行,这样CloudInit知道运行它作为一个shell脚本:

Try adding the following as the first line of the user-data so that CloudInit knows to run it as a shell script:

#!/bin/sh

正如波多黎各指出的那样,你可以删除须藤,因为的用户数据脚本为根的实例的第一次启动运行。

As Rico points out, you can drop the sudo because user-data scripts are run as root on the first boot of the instance.

此外,睡30 CD /数据/ 不提供任何好处,如果这是整体用户数据的脚本。

Also, the sleep 30 and cd /data/ are not providing any benefit if this is the entirety of the user-data script.

这将导致code这样的:

This would result in code like:

"UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
    "#!/bin/sh\n",
    "yum update -y\n",
    "mkdir /data \n",
]]}}

您可以添加光盘回来,如果有要添加到用户数据的脚本。进一步的陈述

You could add the cd back in if there are further statements you are adding to the user-data script.

这篇关于EC2 JSON模板bash脚本不执行这一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆