在bash脚本使用屏幕 [英] Using screen in bash script

查看:188
本文介绍了在bash脚本使用屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑,我用一种超然的屏幕实例,离开它运行的远程服务器上的游戏服务器。
现在我创建可用于关闭服务器,备份所有重要的文件,并重新启动了一个剧本,但是我在与处理屏幕中的一些困难。

I'm running a game server on a remote server where I use a detached screen instance to leave it running. I'm now creating a script that can be used to shut down the server, back up all the vital files and start it up again, however I'm having a few difficulties with dealing with the screen.

我认为我可以(在服务器已经被关闭)切换到分离的屏幕在脚本中调用屏幕-r脚本。
但是,这似乎并没有工作,因为如果我运行外屏脚本,它只是启动服务器在该会话中。

I assumed that I could just switch into the detached screen in the script (after the server had already been shut down) by calling screen -r in the script. But that doesn't seem to work because if I run the script from outside screen it just launches the server in that session.

screen -r
cd ~/servers/StarMade/
sh StarMade-dedicated-server-linux.sh
screen -d

这是我的想法会做的伎俩,但事实并非如此。也许有人可以帮我在这里。我不是一个bash专家。事实上,这是propably我的第一个bash脚本,不包括Hello World的。谢谢你。

This is what I thought would do the trick but it doesn't. Maybe somebody can help me out here. I'm not a bash expert. In fact this is propably my first bash script that doesn't include "Hello World". Thanks.

推荐答案

您的脚本,在你的榜样,会被你的销售,而不是一个在屏幕上得到执行。你需要告诉运转画面读取文件并执行它 - 这就是-X选项是什么

Your script, as in your example, will get executed by your sell, not the one in the screen. You need to tell the running screen to read a file and execute it - that's what the -X option is for.

尝试

tempfile=$(mktemp)
cat > $tempfile <<EOF
cd ~/servers/StarMade/
sh StarMade-dedicated-server-linux.sh
EOF
screen -X readbuf $tempfile
screen -X paste .
rm -f $tempfile

您可以将屏幕在第二终端会话运行,看看会发生什么。

You can leave screen running in a 2nd terminal session to see what happens.

这篇关于在bash脚本使用屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆