使用 Eggdrop & 读取活动日志文件的最后一行.tcl [英] Read The Last Line Of An Active Logfile With Eggdrop & .tcl

查看:26
本文介绍了使用 Eggdrop & 读取活动日志文件的最后一行.tcl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想知道是否可以使用eggdrop和.tcl脚本读取实时日志文件的最后一行,我可以读取日志文件的第一部分,但就是这样,它不再读取了

Hello i was wondering if its possible to read the last line of a realtime logfile with eggdrop and a .tcl script im able to read the first part of the logfile but thats it it doesnt read anymore of it

推荐答案

是否可以对日志文件的一行长度设置上限?如果是这样,很容易得到最后一行:

Is it possible to put an upper bound on the length of a line of the logfile? If so, it's pretty easy to get the last line:

# A nice fat upper bound!
set upperBoundLength 1024

# Open the log file
set f [open $logfile r]
# Go to some distance from the end; catch because don't care about errors here
catch {seek $f -$upperBoundLength end}
# Read to end, stripping trailing newline
set data [read -nonewline $f]
# Hygiene: close the logfile
close $f
# Get the last line
set lastline [lindex [split $data "\n"] end]

请注意,seek 并不是必须;它只是让您不必阅读大部分您可能不想要的文件.

Note that it's not really necessary to do the seek; it just saves you from having to read the vast majority of the file which you presumably don't want.

这篇关于使用 Eggdrop & 读取活动日志文件的最后一行.tcl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆