Gnu-Screen:运行脚本,将命令发送到正在运行的屏幕会话

发布于 2024-07-21 18:28:23 字数 61 浏览 3 评论 0原文

是否可以编写一个脚本来更改名称并打开对当前选项卡的监视(假设它正在屏幕中运行)?

谢谢。

Is it possible to write a script to change the name and turn on monitoring for the current tab assuming that it is being run in screen?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北风几吹夏 2024-07-28 18:28:23

从屏幕手册页:

 -X 将指定的命令发送到正在运行的屏幕会话。   你可以 
         使用 -d 或 -r 选项告诉屏幕仅查找附加的 
         或分离的屏幕会话。   注意这个命令不起作用 
         如果会话受密码保护。 
  

基本上,

screen -X title mynewtitle
screen -X monitor on

如果终端不在屏幕内运行,它会默默地发出错误:

notinscreen:~$ screen -X title mynewtitle
notinscreen:~$

您还可以将命令发送到特定会话,即使在分离时也是如此。 给定一个名为“main”的屏幕会话:

$ screen -S main
[detach from screen session]
$ screen -ls
There is a screen on:
        2073.main       (Detached)
1 Socket in /tmp/uscreens/S-dbr.

..您可以将最后一个活动窗口的标题发送到 blah

$ screen -x main -X title blah

..或一个特定窗口(在此名为 oldwindow)示例):

$ screen -x main -p oldwindow -X title blah

您可以使用进程 ID(来自 screen -ls),而不是使用 -x main,也可以不使用窗口名称(-p oldwindow)您可以使用窗口号:

$ screen -x 2073 -p 0 -X title h

如果只有一个会话,则不必指定会话 PID 或名称。

From the screen manpage:

  -X   Send the specified command to a running screen  session.  You  can
       use  the  -d or -r option to tell screen to look only for attached
       or detached screen sessions. Note that this command  doesn't  work
       if the session is password protected.

Basically, run

screen -X title mynewtitle
screen -X monitor on

If the terminal is not running within screen, it silently errors:

notinscreen:~$ screen -X title mynewtitle
notinscreen:~$

You can also send the command to a specific session, even while detached. Given a screen session named "main":

$ screen -S main
[detach from screen session]
$ screen -ls
There is a screen on:
        2073.main       (Detached)
1 Socket in /tmp/uscreens/S-dbr.

..you can sent the title of the last-active window to blah:

$ screen -x main -X title blah

..or a specific window (named oldwindow in this example):

$ screen -x main -p oldwindow -X title blah

Instead of using -x main you can use the process ID (from screen -ls), also instead of using a window name (-p oldwindow) you can use a window number:

$ screen -x 2073 -p 0 -X title h

If there is only one session, you do not have to specify the session PID or name.

烟火散人牵绊 2024-07-28 18:28:23

我认为这有效:

if [-n "$STY"]; then
    screen -X title "foo"
    screen -X monitor on
fi

I think this works:

if [-n "$STY"]; then
    screen -X title "foo"
    screen -X monitor on
fi
初吻给了烟 2024-07-28 18:28:23

Screen声明了$STY环境变量,你可以尝试使用它。

Screen declares $STY environment variable, you can try use it.

感情洁癖 2024-07-28 18:28:23

您是否希望显示信息或与屏幕会话本身进行交互?
您可以使用以下命令发回消息:(http://www.slac.stanford.edu/comp/unix/package/epics/extensions/iocConsole/screen.1.html#lbAI)

留言热线
屏幕显示
信息性消息和其他
消息行中的诊断。 尽管
该行被分发到出现在
屏幕底部,可以
定义为出现在顶部
编译期间的屏幕。 如果你的
终端有一个状态行定义在
它的 termcap,屏幕将使用它
显示其消息,否则
当前屏幕的行将是
暂时覆盖并输出
会暂时中断。 这
消息行被自动删除
延迟几秒钟后,但可以
也可以提前删除(在终端上
没有状态行)通过开始
类型。

可以使用消息行工具
通过运行在
当前窗口通过 ANSI
隐私消息控制序列。 为了
例如,从外壳内尝试
像这样:

echo '^Hello world from window '$WINDOW'\\'  
  

其中“”是转义符,“^”是
文字向上箭头,'\\' 变成
一个反斜杠。


Are you looking to display information or interact with the screen session itself?
You can send messages back with this: (http://www.slac.stanford.edu/comp/unix/package/epics/extensions/iocConsole/screen.1.html#lbAI)

THE MESSAGE LINE
Screen displays
informational messages and other
diagnostics in a message line. While
this line is distributed to appear at
the bottom of the screen, it can be
defined to appear at the top of the
screen during compilation. If your
terminal has a status line defined in
its termcap, screen will use this for
displaying its messages, otherwise a
line of the current screen will be
temporarily overwritten and output
will be momentarily interrupted. The
message line is automatically removed
after a few seconds delay, but it can
also be removed early (on terminals
without a status line) by beginning to
type.

The message line facility can be used
by an application running in the
current window by means of the ANSI
Privacy message control sequence. For
instance, from within the shell, try
something like:

echo '<esc>^Hello world from window '$WINDOW'<esc>\\' 

where '<esc>' is an escape, '^' is a
literal up-arrow, and '\\' turns into
a single backslash.

最偏执的依靠 2024-07-28 18:28:23

屏幕透明运行,因此很难检测屏幕会话。 如果您尝试发送按键信息,这会起作用,并且如果您不在会话中,则会在您的终端中填充少量垃圾。

Screen runs transparently, so detecting the screen session is hard. If you try sending key presses, that would work, and would fill your terminal with a tiny bit of junk if you're not in a session.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文