Ubuntu 20.04.2 LTS启动后自动执行某个脚本

1.在/etc/init.d/创建你的脚本

cd /etc/init.d/
sudo vim add_static_route_to_34_52.sh

2.在脚本中按如下模板填写

注意### BEGIN INIT INFO和### END INIT INFO之间的都要写,后面有机会研究下为什么。

后面接的就是我的命令,增加一条默认路由

#!/bin/bash
### BEGIN INIT INFO
# Provides:          tuzixini
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: self define auto start
# Description:       self define auto start
### END INIT INFO
sudo route add -host 172.xx.xx.xx gw 172.xx.xx.254

3.修改文件属性 

sudo chmod 775 add_static_route_to_34_52.sh 

4.添加到rc脚本里

sudo update-rc.d add_static_route_to_34_52.sh defaults 90

5.reboot以查看是否生效 

ps:从rc脚本里移除

sudo update-rc.d -f add_static_route_to_34_52.sh remove

参考:https://blog.csdn.net/tuzixini/article/details/95616333

https://blog.csdn.net/edsoki/article/details/107430687

 

posted @ 2021-06-18 18:26  midhillzhou  阅读(676)  评论(0编辑  收藏  举报