【发布时间】:2015-11-10 09:47:30
【问题描述】:
我启动了一个新实例:Ubuntu Server 14.04 LTS (PV),SSD 卷类型
实例启动后,我 ssh 进入服务器,并使用以下命令:
sudo vim /etc/rc.local
将 rc.local 编辑成如下所示:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
mkdir ~/hello
exit 0
我保存文件并注销 ssh 会话。然后从 AWS 在线管理控制台,我停止然后启动我的实例:
但是,当我 ssh 回到我的服务器时,我在 ~/ 目录中看不到 hello 文件夹。 rc.local 是绿色的,这意味着它是可执行的,而且我的命令很简单,所以我不认为命令失败或其他任何事情。
那么有什么方法可以在每次启动 AWS Ubuntu 14.04 实例时运行某些命令?
【问题讨论】:
-
您需要指定文件夹的完整路径,
mkdir /home/ubuntu/hello
标签: linux ubuntu amazon-web-services ssh amazon-ec2