linux rc.local加启动权限,用rc.local设置开机启动

注意: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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值