Code: Select all
set out_chan "#channel"
set txt_file "myfile.txt"
bind pub -|- !read read_proc
proc read_proc { nick uhost hand chan arg } {
global out_chan txt_file
set take_me [open $txt_file r]
set take_all [split [read $take_me] "\n"]
close $take_me
foreach txt_line $take_all {
if {$txt_line != ""} {
putquick "PRIVMSG $out_chan :$txt_line"
}
}
}
putlog "read.tcl blah blah ..."
Ths for the quick replay but i wuld like it to read like hmm last line every x second or if it possibel maybe everytime the file is changed automatictomekk wrote:not tested ;p, try:Code: Select all
set out_chan "#channel" set txt_file "myfile.txt" bind pub -|- !read read_proc proc read_proc { nick uhost hand chan arg } { global out_chan txt_file set take_me [open $txt_file r] set take_all [split [read $take_me] "\n"] close $take_me foreach txt_line $take_all { if {$txt_line != ""} { putquick "PRIVMSG $out_chan :$txt_line" } } } putlog "read.tcl blah blah ..."
Code: Select all
...
set fid [open "| /urs/bin/tail -f /path/to/file" RDONLY]
fconfigure $fid -blocking 0 -buffering line
fileevent $fid readable [list readLine $fid]
...
proc readline {socket} {
while {[gets $socket line] >= 0} {
puthelp "PRIVMSG #channel :$line"
}
if {[eof $socket]} {
close $socket
}
}
Code: Select all
...
set fid [open "/path/to/file" RDONLY]
fconfigure $fid -blocking 0 -buffering line
seek $fid 0 end
fileevent $fid readable [list readLine $fid]
...
proc readline {socket} {
while {[gets $socket line] >= 0} {
puthelp "PRIVMSG #channel :$line"
}
}
Code: Select all
# tomekk, http://forum.egghelp.org/viewtopic.php?t=16929
# output channel
set out_chan "#channel"
# file
set txt_file "myfile.txt"
# check interval (seconds)
set check_interval 10
############################################################
set last_file_mod 0
proc reader_timer { } {
global check_interval
auto_read_proc
if {[string match *reader_timer* [utimers]] != 1} {
utimer $check_interval reader_timer
}
}
proc auto_read_proc { } {
global out_chan txt_file last_file_mod
set file_mtime [file mtime $txt_file]
set file_handle [open $txt_file r]
set get_data [split [read $file_handle] "\n"]
close $file_handle
set last_line [join [lindex $get_data end]]
if {$last_line == ""} {
set last_line [join [lindex $get_data end-1]]
}
if {$last_file_mod != $file_mtime} {
putquick "PRIVMSG $out_chan :$last_line"
set last_file_mod $file_mtime
}
}
if {[string match *reader_timer* [utimers]] != 1} {
utimer $check_interval reader_timer
}
putlog "auto-reader.tcl loaded"
Code: Select all
set last_line [join [lindex $get_data end]]
###should be
set last_line [lindex $get_data end]
Still not working but it send on .rehashnml375 wrote:It's because of the incorrect join I mentioned in my previous post.Code: Select all
set last_line [join [lindex $get_data end]] ###should be set last_line [lindex $get_data end]
yeah, lame, my badnml375 wrote:A suggestion, don't join the result from your lindex operation, as you're working on a list of strings (lindex returns the contained item, not a single-entity list).
Code: Select all
if {![info exists ::last_file_mod]} {set ::last_file_mod 0}
How do you mean where shuld i edit itnml375 wrote:One thing strikes me, last_file_mod is not initialized upon startup, making the comparison "$last_file_mod != $file_mtime" possibly fail. I'd consider adding something like this to the script:Code: Select all
if {![info exists ::last_file_mod]} {set ::last_file_mod 0}
it is initialized, before timer procnml375 wrote:One thing strikes me, last_file_mod is not initialized upon startup, making the comparison "$last_file_mod != $file_mtime" possibly fail. I'd consider adding something like this to the script:Code: Select all
if {![info exists ::last_file_mod]} {set ::last_file_mod 0}
Code: Select all
############################################################
set last_file_mod 0