当前位置:   article > 正文

Ubuntu 20.04 开机执行自定义脚本_ubuntu 22 启动脚本目录

ubuntu 22 启动脚本目录

#1、切换至root,建立rc-local.service文件

vim  /etc/systemd/system/rc-local.service

#2、在里面写入如下内容

  1. [Unit]
  2. Description=/etc/rc.local Compatibility
  3. ConditionPathExists=/etc/rc.local
  4. [Service]
  5. Type=forking
  6. ExecStart=/etc/rc.local start
  7. TimeoutSec=0
  8. StandardOutput=tty
  9. RemainAfterExit=yes
  10. SysVStartPriority=99
  11. [Install]
  12. WantedBy=multi-user.target

#3、然后创建文件:rc.local

vim  /etc/rc.local

 #4、里面写入下面内容(就是开机所要执行的脚本) 

  1. #!/bin/sh -e
  2. ## rc.local
  3. # This script is executed at the end of each multiuser runlevel.
  4. # Make sure that the script will "exit 0" on success or any other
  5. # value on error.
  6. # In order to enable or disable this script just change the execution bits.
  7. # By default this script does nothing.
  8. #start script
  9.   sudo -H -u user1 /bin/bash -c "vncserver :11 -localhost no -geometry 1440x900"
  10.   sudo -H -u user2 /bin/bash -c "vncserver :12 -localhost no -geometry 1440x900"
  11. #end script
  12. echo "added sucessfully!" > /tmp/added_script.log
  13. exit 0
#5、加上权限
chmod +x /etc/rc.local

#6、启动服务

systemctl enable rc-local

#7、开启服务

systemctl start rc-local.service

#8、查看状态

systemctl status rc-local.service

部分内容如下:(注意active (running))

#9、重启并检查test.log文件

vim  /tmp/added_script.log 

#10、如果里面有内容(added sucessfully!),则自启动脚本安装成功。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/55056
推荐阅读
相关标签
  

闽ICP备14008679号