linux开机自启动脚本

查看脚本执行过程命令:bash -x strtst.s

linux开机自启动脚本

CENTOS7开机自启动脚本

1.因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权
chmod +x /etc/rc.d/rc.local
2.赋予脚本可执行权限
假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限
chmod +x /usr/local/script/autostart.sh
3.打开/etc/rc.d/rc.local文件,在末尾增加如下内容
/usr/local/script/autostart.sh

ubuntu20.4开机自启动脚本

1.创建auto.sh执行脚本并授权
mkdir -p /etc/auto
cd /etc/auto
touch auto.sh
chmod 777 *.sh
2.建立autosystem.service文件,内容如下
sudo vim /etc/systemd/system/autosystem.service
[Unit]
Description=autoService
ConditionPathExists=/etc/auto/auto.sh

[Service]
Type=forking
#启动服务的命令(命令必须写绝对路径)
ExecStart=bash /etc/auto/auto.sh
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
#开机启动命令
systemctl enable autosystem.service
#启动
systemctl start autosystem.service
#停止
systemctl stop autosystem.service
#状态
systemctl status autosystem.service
#重启
systemctl restart autosystem.service
posted @ 2021-09-03 16:07  kht  阅读(198)  评论(0编辑  收藏  举报