Ubuntu18.04设置开机自启动脚本

1. 打开编辑rc-local.service:

sudo vim /lib/systemd/system/rc-local.service

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install] #此处Install为自己添加
WantedBy=multi-user.target
Alias=rc-local.service

2. 如果没有/etc/rc.local,创建/etc/rc.local文件

sudo touch /etc/rc.local

3. 编辑

sudo vim /etc/rc.local

4. 按i编辑

#!/bin/bash

#下面键入需要开机执行的命令

sleep2

cd /RobotQt/robot_exe/

source ./run.sh &

5. 按esc键入:wq保存

6. sudo chmod +x /etc/rc.local

7. 启用服务:

sudo systemctl enable rc-local

sudo systemctl start rc-local.service

sudo systemctl status rc-local.service

8. 重启:

reboot

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值