- 創(chuàng)建一個(gè)文件 setup.sh
- 將下面的內(nèi)容復(fù)制進(jìn) setup.sh
#!/bin/bash
echo 創(chuàng)建服務(wù)文件
sudo touch /usr/lib/systemd/system/rc-local.service
sudo echo '''[Unit]
Description="/etc/rc.local Compatibility"
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target''' > /usr/lib/systemd/system/rc-local.service
echo 啟用服務(wù)
sudo systemctl enable rc-local.service
echo 創(chuàng)建rc.local文件
sudo touch /etc/rc.local
echo '''#!/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.
# -----------替換橫杠間的內(nèi)容為需要開機(jī)執(zhí)行的命令---------------
echo rc.local 文件正常!
# -----------替換橫杠間的內(nèi)容為需要開機(jī)執(zhí)行的命令---------------
exit 0''' > /etc/rc.local
echo 授權(quán)
sudo chmod +x /etc/rc.local
echo 測試
sudo sh /etc/rc.local
- 在setup.sh的路徑下打開終端
- 在終端中執(zhí)行 chmod +x setup.sh
- 然后 再運(yùn)行腳本 ./setup.sh