当前位置: 移动技术网 > 网络运营>服务器>Linux > ubuntu中编写shell脚本开机自动启动(推荐)

ubuntu中编写shell脚本开机自动启动(推荐)

2020年03月09日  | 移动技术网网络运营  | 我要评论

编写脚本是为了不用手动去开启各种服务(也是为了偷懒哈哈)

1.进入终端输入

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

touch test.sh

编辑脚本

vim test.sh

test.sh编写脚本内容

 2.编写test.sh脚本

 #!/bin/bash

### begin init info
# provides:     test
# required-start:  $remote_fs $syslog
# required-stop:   $remote_fs $syslog
# default-start:   2 3 4 5
# default-stop:   0 1 6
# short-description: start test
# description:    start test
### end init info

#此处编写脚本内容
cd /home/desktop/
./test.sh
exit 0

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

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

移动文件

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

给文件增加权限

chmod +750 test.sh

设置开机自动启动

sudo update-rc.d test.sh defaults

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

总结

以上所述是小编给大家介绍的ubuntu中编写shell脚本开机自动启动,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网