原文:
How to write screen output to a log file
如何通过screen的命令自定义日志文件?而不是通过配置.screenrc文件去定义日志文件。
通过配置.screenrc文件去定义日志文件可以参考如下:
【整理】CentOS 6.x/7.x screen记录屏幕日志
本文讲解如何不通过screenrc配置文件从而达到screen日志记录。
默认使用 -L 选项去开启日志,默认是 screenlog.0,如果再开启新的会话,那么日志就是screenlog.1,screenlog.2,screenlog.3...我们可以使用 -Logfile 去覆盖默认的规则,自定义自己的日志文件。
默认的screen会话是10秒间隔刷新一次日志,如果想修改这个间隔,可以通过 logfile flush命令去修改间隔时间。
下面命令列出我们自定义日志以及修改日志刷新间隔时间为0:
screen -dmS test -L -Logfile my.log screen -S test -X colon "logfile flush 0^M" # optionally go to session screen -r test # or follow the log ? tail -Fn 0 my.log
上述命令选项意义(此处不做翻译):
- -dm starts the new screen session while remaining detached.
- -S defines the session name.
- -L enables logging to a file at 10 seconds intervals.
- -Logfile defines the file name to log to.
- -X sends a command to an already existing session.
- colon tells the session an internal command is coming up.
- logfile flush tells the screen to set the log interval time in seconds. 0 is realtime.
- ^M sends a CTRL + M key combination to the session. Otherwise you have only typed the command without hitting enter.
For the tail command:
- -F sets tail to keep watching the file for changes.
- -n 0 means to only watch, don’t output older lines.
参考:
https://serverfault.com/questions/192432/how-can-i-force-gnu-screen-to-flush-its-logfile
文章的脚注信息由WordPress的wp-posturl插件自动生成