原文:
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插件自动生成

微信扫一扫,打赏作者吧~
![[已解决]nc命令报错 close: Bad file descriptor](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2022/03/Snipaste_2022-03-18_20-16-48.png&w=280&h=210&zc=1)
![[整理]sublime text3定义快速代码块模板](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/12/1.png&w=280&h=210&zc=1)
![[已解决]win10 bitlocker解除,移除锁感叹号](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/12/Snipaste_2020-12-03_19-59-28.png&w=280&h=210&zc=1)