Ubuntu开机启动脚本
2017-08-09 09:51
399 查看
1.独立脚本
1).编写要执行脚本的sh文件mysetup.sh#!/bin/sh ### BEGIN INIT INFO # Provides: land.sh # Required-start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the svnd.sh daemon # Description: starts svnd.sh using start-stop-daemon ### END INIT INFO #任务脚本 #进入要执行脚本目录 cd /home/cbuav/working/opencv/target_land #取得root权限,'123456'为密码,不用加引号,'ls'无实际作用 echo 123456|sudo -S ls #执行脚本./bin/mywork,sudo -S需要加上 sudo -S ./bin/mywork #任务脚本
注释部分是必须内容,ubuntu 16.04中一定要加上该LSB信息,不然放入启动脚本的时候会报错无法开机启动。
任务脚本中,一般需要用到root权限,取得root权限和实际任务语句最好分开写,有些情况下写在一起不会成功。
2).将该sh文件移动到
/etc/init.d/目录下,并修改权限
cp mysetup.sh /etc/init.d sudo chmod 755 /etc/init.d/mysetup.sh
3).设置启动顺序
cd /etc/init.d sudo update-rc.d mysetup.sh defaults 95
其中数字95是脚本启动的顺序号,按照自己的需要相应修改即可。在你有多个启动脚本,而它们之间又有先后启动的依赖关系时你就知道这个数字的具体作用了。
4).卸载启动脚本
cd /etc/init.d sudo update-rc.d -f mysetup.sh remove
2.在rc.local文件中添加启动脚本
rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令。该脚本位于/etc/路径下,需要root权限才能修改。该脚本具体格式如下:
#!/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. #任务脚本 #打开mate终端,并在其中运行脚本 mate-terminal -x /home/myname/mysetup.sh #任务脚本 exit 0
一定要将命令添加在 exit 0之前
参考文献:
ubuntu 16.04 svn开机启动的两种方法
gnome-terminal技巧
相关文章推荐
- Ubuntu下添加开机启动脚本
- ubuntu编写开机自启动shell脚本
- Linux(Ubuntu)下设置开机启动shell脚本执行Java程序jar包
- Ubuntu下添加开机启动脚本
- ubuntu开机启动Mongo脚本以及使用root权限执行的脚本(快捷方式)
- Ubuntu 14.04设置开机启动脚本的方法
- Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启动程序/服务)
- Ubuntu下添加开机启动脚本
- ubuntu开机启动shell脚本
- Ubuntu 创建开机启动脚本的一种方法(rc.local)
- [转载]Ubuntu下添加开机启动脚本
- Ubuntu 16.04 server版本开机启动脚本不支持
- Ubuntu用户自定义脚本开机启动
- 为ubuntu创建开机启动脚本
- Ubuntu下添加开机启动脚本简易方法
- Ubuntu 14.04 添加删除开机启动脚本
- ubuntu 设置Path 开机启动脚本
- Ubuntu下添加开机启动脚本的方法
- Ubuntu 16添加开机启动脚本
- Ubuntu下添加开机启动脚本