Gnu-Screen: Run script that sends commands to the screen session it is being run in

强颜欢笑 提交于 2019-11-29 13:57:28

问题


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.


回答1:


I think this works:

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



回答2:


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.




回答3:


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




回答4:


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 '' is an escape, '^' is a literal up-arrow, and '\' turns into a single backslash.




回答5:


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.



来源:https://stackoverflow.com/questions/899609/gnu-screen-run-script-that-sends-commands-to-the-screen-session-it-is-being-run

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!