目录
[TOC]
问题
在使用screen的时候,如果有大量屏幕滚动,则会造成上下查阅不便,解决办法是将screen输出的所有内容都写入日志中。
解决办法
先打开screen配置文件screenrc
:
vim /etc/screenrc
在screenrc
最后一行粘贴以下内容:
logfile /var/log/screenlog_%S.log
启动screen的时候要这样:
screen -SL sockname
然后在/var/log/
下就会生成一个以screenlog
开头的日志文件了
比较烦人的是,我这里screenlog_%S.log
这个日志文件用vim查看会出现颜色代码,极为影响观感:
5 root@instance-0647:/var/log# ll /var/lo^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^H^[[K^Gll
6 total 60316
7 drwxrwxr-x 9 root syslog 4096 Feb 16 14:42 ^[[0m^[[01;34m.^[[0m/
8 drwxr-xr-x 13 root root 4096 Apr 20 2022 ^[[01;34m..^[[0m/
没办法,查看这个日志文件的时候就用tail
吧,不会出现乱码。
P.S.网上有人用的是logfile /var/log/screenlog_%t.log
,这种方式方式比较麻烦,使用时还要多传一个参数,如screen -S sockname -t titlename -L
,比较麻烦。
附screen说明
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]
Options:
-4 Resolve hostnames only to IPv4 addresses.
-6 Resolve hostnames only to IPv6 addresses.
-a Force all capabilities into each window's termcap.
-A -[r|R] Adapt all windows to the new display width & height.
-c file Read configuration file instead of '.screenrc'.
-d (-r) Detach the elsewhere running screen (and reattach here).
-dmS name Start as daemon: Screen session in detached mode.
-D (-r) Detach and logout remote (and reattach here).
-D -RR Do whatever is needed to get a screen session.
-e xy Change command characters.
-f Flow control on, -fn = off, -fa = auto.
-h lines Set the size of the scrollback history buffer.
-i Interrupt output sooner when flow control is on.
-l Login mode on (update /var/run/utmp), -ln = off.
-ls [match] or
-list Do nothing, just list our SockDir [on possible matches].
-L Turn on output logging.
-Logfile file Set logfile name.
-m ignore $STY variable, do create a new screen session.
-O Choose optimal output rather than exact vt100 emulation.
-p window Preselect the named window if it exists.
-q Quiet startup. Exits with non-zero return code if unsuccessful.
-Q Commands will send the response to the stdout of the querying process.
-r [session] Reattach to a detached screen process.
-R Reattach if possible, otherwise start a new session.
-s shell Shell to execute rather than $SHELL.
-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title Set title. (window's name).
-T term Use term as $TERM for windows, rather than "screen".
-U Tell screen to use UTF-8 encoding.
-v Print "Screen version 4.08.00 (GNU) 05-Feb-20".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x Attach to a not detached screen. (Multi display mode).
-X Execute <cmd> as a screen command in the specified session.