• 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

  • 相关阅读:
    Rust 变量
    Rust-lang(hello world 续)
    Rust-lang(hello world)
    Java 1.8 ASM ClassReader failed to parse class file
    Sqoop使用笔记
    Jstorm
    从flume到kafka,日志收集
    vim-3-插件管理
    vim-2-使用进阶
    Git-Repo-Gerrit-1-Git介绍,安装和配置
  • 原文地址:https://www.cnblogs.com/midhillzhou/p/14900827.html
Copyright © 2020-2023  润新知