Ubuntu20.04如何实现开机自动运行脚本

sh/bash/dash/ksh/zsh等Shell脚本
回复
hxh342523
帖子: 4
注册时间: 2020-02-08 23:10
系统: win10

Ubuntu20.04如何实现开机自动运行脚本

#1

帖子 hxh342523 » 2020-07-20 22:39

我的目的是想开机自动运行主目录下的frpc_linux_amd64内网穿透程序。
之前在19.10时,我简单写了一个.sh脚本:nohup ./frpc_linux_amd64 &,修改了执行权限,然后通过图形界面的“启动应用程序”添加了这个.sh脚本,就能实现我的目的。
后来升级到了20.04,依然可用。
再后来,这个frp服务有了重大更新,老版本frp不可用了,无奈更新了frpc_linux_amd64程序,同时它的启动参数也改变了:
./frpc_linux_amd64 -f abcedfghabcedfgh:6666。
于是,我更改.sh脚本:nohup ./frpc_linux_amd64 -f abcedfghabcedfgh:6666 &,但是,这就不管用了。文件名、路径啥的都没改,也不知道哪里的问题。
如果我直接在终端执行:./frpc_linux_amd64 -f abcedfghabcedfgh:6666,没问题;
如果我直接在终端执行.sh脚本,也没问题。

图形界面下不管用,我又参考网上一些方法,比如:https://www.cnblogs.com/wal1317-59/p/12693309.html ,还是不行。

大概就是这么个情况,恳请有经验的大佬帮忙指点一下,我可能哪里出了问题。
ffr0
帖子: 1
注册时间: 2020-07-21 1:10
系统: win10

Re: Ubuntu20.04如何实现开机自动运行脚本

#2

帖子 ffr0 » 2020-07-21 1:41

先尝试直接在/etc/rc.local里面调用你的脚本。如果无效,就让它在screen或者tmux中运行吧。
screen -dm script.sh
可以让screen在后台运行script.sh,如果你需要进入查看输出内容,用screen -x就可以进入,看完用Ctrl+A d脱离screen让它在后台继续运行。
tmux类似
tmux new-session -d -s "myTempSession" my_script.sh
onlylove
论坛版主
帖子: 5230
注册时间: 2007-01-14 16:23

Re: Ubuntu20.04如何实现开机自动运行脚本

#3

帖子 onlylove » 2020-07-21 12:33

你看的文章太老了

现在想要在rc.local里面添加启动,首先要启用rc.local.service

代码: 全选

systemctl enable rc.local.service
或者用systemd的timer来做,不过略微麻烦一点
http://www.ruanyifeng.com/blog/2018/03/ ... timer.html
hxh342523
帖子: 4
注册时间: 2020-02-08 23:10
系统: win10

Re: Ubuntu20.04如何实现开机自动运行脚本

#4

帖子 hxh342523 » 2020-07-21 16:01

onlylove 写了: 2020-07-21 12:33 你看的文章太老了

现在想要在rc.local里面添加启动,首先要启用rc.local.service

代码: 全选

systemctl enable rc.local.service
或者用systemd的timer来做,不过略微麻烦一点
http://www.ruanyifeng.com/blog/2018/03/ ... timer.html
谢谢你,终于搞定了!
回复