Linux开机运行脚本

2023-05-10  本文已影响0人  咖啡机an

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
上一篇 下一篇

猜你喜欢

热点阅读