Ubuntu下设置开机后自动运行命令

第一种是编辑/etc/下的rc.local脚本,

然后把对应的需要执行的脚本写在exit 0前面,在ubuntu16.06上亲测无效

第二种则是编辑一个shell脚本,然后在shell脚本中写入自己开机之后需要执行的命令,然后把该脚本拷贝进/etc/init.d/文件夹下,赋予可执行的权限,然后一行命令sudo update-rc.d 你的脚本 defaults 90

比如我这里先写一个开机自动挂载两个盘以及frpc内网穿透的服务,

然后命名为mount_and_frpc.sh,从桌面拷贝到文件夹/etc/init.d/下:sudo cp ./mount_and_frpc.sh /etc/init.d/,并且赋予可执行权限sudo chmod 775 ./mount_and_frpc.sh

然后执行该命令:sudo update-rc.d mount_and_frpc.sh defaults 90,然后会报如下错误:missing LSB tags and overrides,这参考下面这俩个链接

http://blog.bbzhh.com/index.php/archives/134.html, http://www.linuxdiyf.com/linux/26896.html

个时候需要在执行的命令前面加上这样一段话:

然后执行:sudo update-rc.d mount_and_frpc.sh defaults 90,重启reboot即可

同样的,如果想取消该开机自启项,需要执行如下命令

cd /etc/init.d

sudo update-rc.d -f mount_and_frpc.sh remove

猜你喜欢

转载自www.linuxidc.com/Linux/2017-09/147178.htm
今日推荐