如何在屏幕会话中编写 gnu screen 脚本来打开新窗口并在其中运行命令?
在屏幕会话中,我想运行一个打开的 shell 脚本 在同一会话中创建一些新屏幕窗口并开始运行一些 其中的程序。
我需要这样的脚本:
screen -t newWindow
[switch to newWindow and execute a command]
screen -t newWindow2
[switch to newWindow2 and execute a command]
我不知道如何实现我在括号中描述的效果。 有什么线索吗?请注意,这不是我将运行来启动屏幕会话的脚本。我需要这个脚本可以在现有的屏幕会话中运行,以便向会话添加新窗口。
From within a screen session, I'd like to run a shell script that opens
a few new screen windows in the same session and start running some
programs in them.
I need a script like this:
screen -t newWindow
[switch to newWindow and execute a command]
screen -t newWindow2
[switch to newWindow2 and execute a command]
I don't know how to accomplish the effect I describe in the brackets.
Any clues? Please note that this is not a script I'll be running to start a screen session. I need this script to be runnable within an existing screen session, in order to add new windows to the session.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:您无法从屏幕会话中启动按以下方式工作的脚本。并且它不会在会话中打开任何选项卡...它更多的是相关提示,而不是问题的真正答案。
还有其他解决方案,如果您接受通过运行进程来进行屏幕会话...
新会话script
init 脚本(此处为“init.sh”)
注入脚本(此处为 screenexec)
通过使用这种方式,您应该可以轻松地在屏幕中注入代码,如果您的脚本像守护进程一样运行,那么这很有趣......
对于那些喜欢使用 python 脚本的人来说,我制作了一个小库来创建会话、关闭会话、注入命令: ScreenUtils.py
这是一个小项目,不处理多窗口屏幕会话。
忘了说我很久以前就用它制作了一个真正的Python库: https://github.com/Christophe31/screenutils
Note: you can't launch script working following way from a screen session. And it will open in session no tabs... Its more a related tip than a real answer to the question.
There is an other solution, if you accept to have a screen session by running process...
new session script
init script (here "init.sh")
injection script (here screenexec)
By using this way, you should inject code easily in your screens, interesting if your script act like a deamon...
For those who prefer script in python, I've made a small lib to create sessions, close sessions, inject commands: ScreenUtils.py
It's a small project, which don't handle multiwindows screen sessions.
Forgot to mention I made a real python library out of it long ago: https://github.com/Christophe31/screenutils
在屏幕内运行此脚本可以实现我认为您想要的功能:
Running this script inside screen does what I think you want: