美文网首页
Linux开机运行脚本

Linux开机运行脚本

作者: 咖啡机an | 来源:发表于2023-05-10 09:12 被阅读0次

1.准备sh脚本,reboort.sh

#!/bin/bash
#这里可替换为你自己的执行程序,其他代码无需更改
cd /usr/nginx/sbin/
./nginx

2.修改/etc/rc.d/rc.local启动文件

在linux各项服务启动完毕之后,会运行/etc/rc.d/rc.local,修改后的内容如下

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
#下面添加需要启动的脚本路径
/opt/reboot/reboort.sh

3.更改文件权限为可运行

修改后,就可以重启服务器测试效果了,reboot

#自己准备的脚本
chmod  +x /opt/reboot/reboort.sh
#系统的文件
chmod +x /etc/rc.d/rc.local

相关文章

网友评论

      本文标题:Linux开机运行脚本

      本文链接:https://www.haomeiwen.com/subject/hxgdsdtx.html