Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get linux screen title from command line

How can I fetch the title of a screen session from the command line?

like image 437
Kristian Stauffer Avatar asked Nov 10 '12 12:11

Kristian Stauffer


People also ask

What is the command to check screen in Linux?

Enable Screen Logging in Linux To activate the screen logging function, just press “Ctrl-A” and “H“.

How do you rename a Linux window?

While in a screen session press Ctrl - a + A (it's an uppercase a, i.e. Shift + a ), type the new name, and press Enter.

What is CLI screen?

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.


1 Answers

I came up with a very small and simple python script with pexpect to do it.

It is handy in multiuser environments where some host is reserved and status is written to screen title by user. It works for me, feel free to make it better. In order to fetch specific session title, you need to modify the script and call for correct session.

If you run this through remote connection as local script (through SSH for example), remember to set export TERM=xterm before execution.

try:
    import pexpect
    import sys
    child=pexpect.spawn('screen -x')
    child.sendcontrol('a');
    child.send('A');
    i = child.expect('Set window.*')
    child.sendcontrol('c');
    child.sendcontrol('a');
    child.send('d');
    TITLE=str(child.after)
    TITLE_P=TITLE.split('7m')
    if str(TITLE_P[-1]) == '':
        print 'Title not found'
    else:
        print str(TITLE_P[-1])
except:
    print 'Could not check screen Title'
like image 135
Kristian Stauffer Avatar answered Oct 02 '22 12:10

Kristian Stauffer