使用Eggdrop&读取活动日志文件的最后一行.tcl

时间:2012-01-22 00:58:12

标签: tcl eggdrop

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

1 个答案:

答案 0 :(得分: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并非真正必要;它只是让你不必阅读你可能不想要的绝大多数文件。