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
创建启动项