Ubuntu14.04设置开机启动脚本(转)

原文:https://www.magentonotes.com/ubuntu-config-autostart-shell-script.htmlhtml

方法一:将脚本添加到文件/etc/rc.local

/etc/rc.local脚本是一个ubuntu开机后会自动执行的脚本,咱们能够在该脚本内添加命令行指令。该文件须要root权限才能修改。该脚本具体格式以下,shell

注意,必定要将命令添加在 exit 0以前,好比我用VirtualBox启动Ubuntu虚拟机,虚拟机上配置的 网络链接是桥接模式,但Ubuntu每次启动后,网络ubuntu

都链接不上,须要启动后,本身再执行NetworkManager命令,这里,咱们就能够将这个命令的执行放在/etc/rc.local里面,bash

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.
 
 
# add by zhj,启动网络链接
NetworkManager
 
exit 0

 

方法二:将脚本文件放在/etc/init.d/目录下

要注意的是,/etc/init.d/目录下的脚本的内容是有格式要求的,不能随便写,具体格式本身在网上搜吧网络

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

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

2,设置权限spa

1
sudo chmod 755 new_service.sh

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

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

4,将脚本添加到启动脚本
执行以下指令,在这里90代表一个优先级,越高表示执行的越晚code

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
相关文章
相关标签/搜索