This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Scan log for changes and process (events)

Help for those learning Tcl or writing their own scripts.
Post Reply
s
supersam
Voice
Posts: 2
Joined: Wed Aug 25, 2010 4:37 pm

Scan log for changes and process (events)

Post by supersam »

So I would like to get my eggdrop to parse a file continually. And if a string/regexp matches then follow up with some action.

The follow up is easy - just not sure how to scan.

Thanks in advance.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Hi there. Sounds like you are wanting to either output the whole file line by line, or else create a list containing each line. To do the first, you can do do something like this:

Code: Select all

set fs [open "file.ext"]
 while {[gets $fs line] >= 0} {
    <actions here>
 }
 close $fs
If you want to create a list of file line elements:

Code: Select all

 set fs [open "file.ext"]
 set lines [split [read -nonewline $fs] \n]
   close $fs
Be sure to close the file when you are done with it. Leaving one open and opening it again makes for a badly behaved eggie, hehe.
s
supersam
Voice
Posts: 2
Joined: Wed Aug 25, 2010 4:37 pm

Post by supersam »

Thank for the reply. I was looking more for a tail -f script. In the end I went from a cron job.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Oh, okay, my bad... you could do something with the exec command also. You can put the command in as you would normally, just use exec before.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Code: Select all

set fs [open "|tail -f file.log"]
fconfigure $fs -blocking 0 -buffering line
fileevent $fs readable [list output $fs]
proc output {fs} {putserv "privmsg #chan :[gets $fs]"}
Post Reply