您的位置:首页 > 其它

ubuntu14.04 设置开机自启动脚本

2017-04-07 20:53 471 查看
方法一, 编辑rc.local脚本

ubuntu开机之后会执行/etc/rc.local文件中的脚本。所以可以直接在/etc/rc.local中添加启动脚本。脚本要添加到 exit 0 之前。

以下是rc.local 初始状态,在exit 0之前添加需要执行的操作即可。

#!/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


方法二, 添加一个ubuntu的开机启动服务

分为以下几个步骤:

1)新建一个脚本文件 new_services.sh

#!/bin/bash
# command content
exit 0


2)将脚本放置到启动目录下

sudo mv new_services.sh /etc/init.d/


3)设置权限

sudo chmod 755 new_services.sh


4)将脚本添加到启动脚本

cd /etc/init.d/
sudo update-rc.d new_serviecs.sh defaults 90


这里90表明一个优先级,越高表示执行的越晚。

移除ubuntu开机脚本

sudo update-rc.d -f new_services.sh remove
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: