Linux中一键创建rc.local的shell脚本

本文提供了一个shell脚本,用于在当前主流的Linux发行版中创建rc.local服务,这些发行版已将rc服务化。脚本已在Debian和OpenEuler上测试通过,包括创建rc-local.service单元文件和rc.local文件,并设置相关权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、前言

在当下,主流的Linux已经没有rc.local这个文件了,因为这些主流Linux已经将rc服务化了,因此如果需要使用rc.local,则需要自行创建相关文件,为简化操作,特将相关操作整理为shell脚本,该脚本可一键执行,代码如下:

#相关代码已经在debian和OpenEuler上测试通过!

#/bin/bash
function createRc_local(){
        cat << EOF > /etc/systemd/system/rc-local.service
[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target
EOF

        systemctl enable rc-local.service
        cat << EOF > /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
EOF

        chmod +x /etc/rc.local
}

createRc_local
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值