注意:rc.local脚本里面启动的用户默认为root权限。
rc.local脚本
rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令。该脚本位于/etc/路径下,需要root权限才能修改。
该脚本具体格式如下:
xinlin@iZ239r252v4Z:/usr$ cat /etc/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.
exit 0
xinlin@iZ239r252v4Z:/usr$
注意: 一定要将命令添加在exit 0之前。里面可以直接写命令或者执行Shell脚本文件sh。
脚本不启动的可能原因:
1, rc.local文件头部/bin/sh修改为/bin/bash
2, 如果是执行sh文件,那么要赋予执行权限sudo chmod +x xxx.sh
还有一个关于设置Linux自启动服务器的帖子:在ubuntu中添加删除自启动service