Centos系统启动自动运行脚本

论坛 期权论坛 脚本     
匿名技术用户   2021-1-7 02:43   64   0

1、新建自定义脚本start.sh

#!/bin/bash 
# This is start hgfs
cd /opt/sh/start
sh ./hgfs.sh

2、定义需要执行的脚本,如(共享文件):hgfs.sh

#!/bin/bash 
# This is start hgfs
sudo vmhgfs-fuse .host:/ /mnt/hgfs

目录结构

3、执行命令:

cd etc/rc.d/

4、编辑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
cd /opt/sh/start
sh ./start.sh
exit 0

5、赋予权限

chmod +777 rc.local

6、查看rc.local状态是否正常

systemctl status rc-local

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP