您好,我想知道是否可以使用 eggdrop 和 .tcl 脚本读取实时日志文件的最后一行,我能够读取日志文件的第一部分,但仅此而已,它不再读取它
问问题
2110 次
1 回答
2
是否可以在日志文件的一行长度上设置上限?如果是这样,很容易得到最后一行:
# 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
; 它只是使您不必阅读您可能不想要的绝大多数文件。
于 2012-01-22T11:13:04.527 回答