首页 技术 正文
技术 2022年11月19日
0 收藏 364 点赞 4,019 浏览 980 个字

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

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

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

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

都连接不上,需要启动后,自己再执行NetworkManager命令,这里,我们就可以将这个命令的执行放在/etc/rc.local里面,

1234567891011121314 #!/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.sh

1234 #!/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表明一个优先级,越高表示执行的越晚

12 cd /etc/init.d/sudo update-rc.d new_service.sh defaults 90
移除Ubuntu开机脚本
1 sudo update-rc.d -f new_service.sh remove
上一篇: mimkatz 用法
下一篇: jquery重置表单
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905