ubuntu 20.04.1 LTS 开机自启动脚本服务开启 打开终端运行

 

sudo vi /etc/systemd/system/rc-local.service

写入以下内容:

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local  #脚本文件位置
 
[Service]
Type=forking
ExecStart=/etc/rc.local start  #配置的脚本文件rc.local为start
TimeoutSec=0    
StandardOutput=tty  #标准输出
RemainAfterExit=yes
SysVStartPriority=99  #优先级,当有多个开机启动文件时可以设置不同的值
 
[Install]
WantedBy=multi-user.target

sudo vi /etc/rc.local

示例写入开启frp:

#!/bin/bash
#
# 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.

echo "test....." > /var/test.log


#your shell
#excample:
/home/inspur/Documents/frp/frpc -c /home/inspur/Documents/frp/frpc.ini
#或
#打开新终端运行;分号隔开多条命令;exec bash防止终端一闪消失
gnome-terminal -- bash -c "cd /home/inspur/Documents/frp/;./frpc -c ./frpc.ini;exec bash"


exit 0

更改权限:

sudo chmod 775 /etc/rc.local

开启服务:

sudo systemctl enable rc-local

sudo systemctl start rc-local.service

链接:

sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

重启电脑查看:

sudo reboot

cat /var/test.log

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

百年人生当疯狂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值