How can I fetch the title of a screen
session from the command line?
Enable Screen Logging in Linux To activate the screen logging function, just press “Ctrl-A” and “H“.
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.
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With