ubuntu中编写shell脚本开机自动启动

编写脚本是为了避免用手动去开启各类服务(也是为了偷懒哈哈)python

1.进入终端输入linux

建立一个后缀为.sh的脚本文件vim

touch test.sh

编辑脚本bash

vim test.sh

test.sh编写脚本内容ide

 2.编写test.sh脚本ui

 

1 #!/bin/bash
 2 
 3 ### BEGIN INIT INFO
 4 # Provides:          test
 5 # Required-Start:    $remote_fs $syslog
 6 # Required-Stop:     $remote_fs $syslog
 7 # Default-Start:     2 3 4 5
 8 # Default-Stop:      0 1 6
 9 # Short-Description: start test
10 # Description:       start test
11 ### END INIT INFO
12 
13 #此处编写脚本内容
14 cd /home/Desktop/
15 ./test.sh
16 exit 0

以#!/bin/bash开头 中间写脚本内容 exit0结尾 code

3.移动test.sh文件到/etc/init.d目录下ip

移动文件rem

sudo mv test.sh /etc/init.d/

给文件增长权限it

chmod +750 test.sh

设置开机自动启动

sudo update-rc.d test.sh defaults

 4.这样一个开机自动化脚本就完成咯

相关文章
相关标签/搜索