我想出了一个非常小且简单的 python 脚本来pexpect完成它。
它在多用户环境中非常方便,其中保留了某些主机并且用户将状态写入屏幕标题。它对我有用,请随意使其变得更好。为了获取特定的会话标题,您需要修改脚本并调用正确的会话。
如果您通过远程连接作为本地脚本运行它(例如通过 SSH),请记住export TERM=xterm在执行之前进行设置。
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'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
387 次 |
| 最近记录: |