Linux开机运行脚本

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容