Ubuntu系统如何设置开机自启动shell脚本?

415 阅读1分钟

在Ubuntu系统中设置开机自启动Shell脚本的方法如下:

  1. 创建Shell脚本:
    在任意位置创建你的Shell脚本文件,例如 myscript.sh

  2. 给脚本文件添加可执行权限:

    chmod +x /path/to/myscript.sh
    
  3. 将脚本移动到 /etc/init.d/目录下:

    sudo mv /path/to/myscript.sh /etc/init.d/
    
  4. 使用 update-rc.d命令添加脚本到启动项:

    sudo update-rc.d myscript.sh defaults
    
  5. 确保脚本已经成功添加到启动项:

    ls /etc/rc*.d/
    

    确认在输出中能够看到 /etc/rcX.d/SXXmyscript.shX为数字,XX为优先级)。

现在,你的Shell脚本将会在Ubuntu系统开机时自动执行。请确保脚本中的逻辑是正确的,以免对系统造成不必要的影响。


香港五网CN2网络云服务器链接:www.tsyvps.com

蓝易云香港五网CN2 GIA/GT精品网络服务器。拒绝绕路,拒绝不稳定。