Ubuntu 16.04添加开机启动脚本的方法

A 自带开机脚本

/etc/rc.local脚本是一个ubuntu16.04及其以前的系统中自带的开机脚本,在没有修改之前里面内容如下。

 

[plain]  view plain  copy
 
 
  1. #!/bin/sh -e  
  2. #  
  3. # rc.local  
  4. #  
  5. # This script is executed at the end of each multiuser runlevel.  
  6. # Make sure that the script will "exit 0" on success or any other  
  7. # value on error.  
  8. #  
  9. # In order to enable or disable this script just change the execution  
  10. # bits.  
  11. #  
  12. # By default this script does nothing.  
  13.     
  14. exit 0  
可以把开机要执行的命令放到 exit0 前面。
 

B 添加开机脚本

1,新建个脚本文件new_service.sh

 

 

[plain]  view plain  copy
 
 
  1. #!/bin/bash  
  2. # command content  
  3.     
  4. exit 0  
 

2,设置权限

 

[plain]  view plain  copy
 
 
  1. sudo chmod 755 new_service.sh  

 

3,把脚本放置到启动目录下

 

[plain]  view plain  copy
 
 
  1. sudo mv new_service.sh /etc/init.d/  
 

 

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

执行如下指令,在这里90表明一个优先级,越高表示执行的越晚

 

[plain]  view plain  copy
 
 
  1. cd /etc/init.d/  
  2. sudo update-rc.d new_service.sh defaults 90  
 

 

移除Ubuntu开机脚本

 

[plain]  view plain  copy
 
 
  1. sudo update-rc.d -f new_service.sh remove
本人亲手打造语音智能灯安利
本人亲手打造语音智能灯安利

 

  • 5
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值