Ubuntu 20.04.03LTS开机自启动脚本

SSH


此处记录5种方法,经过粗略测试,有好使的,也有不好使的,根据情况自行选用。


1

新建.sh

cp .sh /etc/init.d/

chmod 775 .sh

update-rc.d .sh defaults 90

reboot

取消

cd /etc/init.d/

update-rc.d -f .sh remove

参考:

https://www.linuxdiyf.com/linux/26896.html

https://www.cnblogs.com/wal1317-59/p/12693309.html

.sh参考

#!/bin/sh
### BEGIN INIT INFO
# Provides:          svnd.sh
# Required-start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the svnd.sh daemon
# Description:       starts svnd.sh using start-stop-daemon
### END INIT INFO

echo "HELLOWORLD" > /home/dream_haohao/test.log

cd /home/dream_haohao/Dream_haohao
xdg-open Dream_haohao.txt
xdg-open SSH.md

测试失败


2

cd /etc/systemd/system

mkdir svc-test.service

[Unit]
Description=svc-test
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/bash /home/dream_haohao/auto_start.sh
  // 必须为绝对路径

[Install]
WantedBy=multi-user.target


#!/bin/bash

echo "HELLOWORLD" > /home/dream_haohao/test.log

cd /home/dream_haohao/Dream_haohao
xdg-open Dream_haohao.txt

xdg-open SSH.md


chmod 777 svc-test.service

systemctl daemon-reload

systemctl ensble svc-test.service

reboot

取消

systemctl disable svc-test.service

手动停止 – systemctl stop svc-test

手动启动 — systemctl start svc-test

查看状态 — systemctl status svc-test

参考 https://blog.csdn.net/qq_43030934/article/details/116238278?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-1.no_search_link&spm=1001.2101.3001.4242

可以打印文件

但是打不开文件

可以连续执行(重复)


3

ls /lib/systemd/system —> rc-local.service

vim rc-local.servixe

添加

[Install]

WantedBy=multi-user.target  

Alias=rc-local.service

cd /etc/rc.local

如果没有 mkdir rc.local

编写 #!/bin/sh

chmod 777 rc.local

ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/

reboot

取消

把加的东西都去掉

测试失败


4

编写 .sh

cp .sh /etc/profile.d/

进入桌面前会先运行

只运行一次


5

搜索 启动

编写 .sh

创建启动项

进入桌面后启动

只运行一次

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值