| View previous topic :: View next topic |
| Author |
Message |
supersam Voice
Joined: 25 Aug 2010 Posts: 2
|
Posted: Wed Aug 25, 2010 4:43 pm Post subject: Scan log for changes and process (events) |
|
|
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. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Wed Aug 25, 2010 8:01 pm Post subject: |
|
|
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: |
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: |
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. |
|
| Back to top |
|
 |
supersam Voice
Joined: 25 Aug 2010 Posts: 2
|
Posted: Thu Aug 26, 2010 2:25 pm Post subject: |
|
|
| Thank for the reply. I was looking more for a tail -f script. In the end I went from a cron job. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Thu Aug 26, 2010 11:36 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Mon Sep 06, 2010 8:07 pm Post subject: |
|
|
| Code: | 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]"} |
|
|
| Back to top |
|
 |
|