服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Ubuntu - Ubuntu 14.04设置开机启动脚本的方法

Ubuntu 14.04设置开机启动脚本的方法

2021-12-09 15:45Ubuntu教程网 Ubuntu

这篇文章主要给大家介绍了Ubuntu 14.04设置开机启动脚本的方法,文中通过代码介绍的很详细,相信对大家的理解和学习具有一定的参考借鉴价值,有需要的朋友们下面来跟着小编一起学习学习吧。

rc.local脚本

rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令。该脚本位于/etc/路径下,需要root权限才能修改。

该脚本具体格式如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/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

注意: 一定要将命令添加在 exit 0之前

如何给ubuntu添加一个开机启动脚本

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

?
1
2
3
4
#!/bin/bash
# command content
 
exit 0

2,设置权限

?
1
sudo chmod 755 new_service.sh

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

?
1
sudo mv new_service.sh /etc/init.d/

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

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

?
1
2
cd /etc/init.d/
sudo update-rc.d new_service.sh defaults 90

移除Ubuntu开机脚本

?
1
sudo update-rc.d -f new_service.sh remove

总结

以上就是这篇文章的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

原文链接:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.html

延伸 · 阅读

精彩推荐