AWS Ubuntu 14.04 /etc/rc.local不起作用?

时间:2015-08-17 16:52:42

标签: linux ubuntu amazon-web-services ssh amazon-ec2

我推出了一个新的实例: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在线管理控制台,我停止然后启动我的实例:

enter image description here

然而,当我回到我的服务器时,我没有在〜/目录中看到一个hello文件夹。 rc.local是绿色的,这意味着它是可执行的,我的命令非常简单,所以我不认为命令失败或任何事情。

因此,每次启动AWS Ubuntu 14.04实例时,是否有任何方法可以运行某些命令?

1 个答案:

答案 0 :(得分:1)

您选择的测试很简单,但选择不当。

~/是当前用户的主目录。

/etc/rc.local正在运行时,当前用户不是“ubuntu”。当前用户是“root”。因此~/如果引用任何内容,则不会引用/home/ubuntu。更有可能的是,您会在/root/hello找到新文件夹。

如评论中所述,您需要使用完整路径来获得所需的结果。

相关问题