0

当文件大小或行数更改时,我想从 fail2ban 日志中读取所有新行。我只想将 fail2ban 日志中的新行打印到指定通道。

我尝试:

bind time - * checklogs
set kanal "#logzzz"
set logf2b "/var/log/fail2ban.log"

proc linecount {file} {
        set i 0
        set fid [open $file r]
        while {[gets $fid line] > -1} {incr i}
        close $fid
        return $i
}

set oldlines [linecount $logf2b]
set filesize [file size $logf2b]

proc checklogs {min hour day mon year} {
    global kanal oldlines logf2b filesize
    if {[file size $logf2b] != $filesize} {
        set newfile [open $logf2b "r"]
        while {1} {
            set line [gets $newfile $oldlines]
            if {[eof $newfile]} {
                close $newfile
                break
            }
            putserv "PRIVMSG $kanal :Fail2Ban $line"
        }
    } else { putserv "PRIVMSG $kanal :No new fail2ban logs!" }
}

但不起作用:/

任何解决方案或解释如何制作?

4

0 回答 0