zoukankan      html  css  js  c++  java
  • Linux 开机自动启动脚本

    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
     
    cd /etc/init.d
    sudo update-rc.d mysetup.sh defaults 95
    

    其中数字95是脚本启动的顺序号,按照自己的需要相应修改即可。在你有多个启动脚本,而它们之间又有先后启动的依赖关系时你就知道这个数字的具体作用了。

    3)卸载启动脚本

     cd /etc/init.d
    sudo update-rc.d -f mysetup.sh remove
    
  • 相关阅读:
    OpenStack 发行版本
    刷新linux硬盘存储接口
    LVM实践
    LVM man帮助
    ansible --help 文档
    nmcli connection modify eth1 ipv4.addr "192.168.31.23" ipv4.method manual
    自己动手使用, MetaWeblog 发布博客(cnblogs)
    测试图片上传 on Markdown editor
    大批量更新数据mysql批量更新的四种方法
    PHP print_r 转换/还原为数组
  • 原文地址:https://www.cnblogs.com/qccz123456/p/11688880.html
Copyright © 2011-2022 走看看