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.
Help for those learning Tcl or writing their own scripts.
supersam
Voice
Posts: 2 Joined: Wed Aug 25, 2010 4:37 pm
Post
by supersam » Wed Aug 25, 2010 4:43 pm
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.
Luminous
Op
Posts: 146 Joined: Fri Feb 12, 2010 1:00 pm
Post
by Luminous » Wed Aug 25, 2010 8:01 pm
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.
supersam
Voice
Posts: 2 Joined: Wed Aug 25, 2010 4:37 pm
Post
by supersam » Thu Aug 26, 2010 2:25 pm
Thank for the reply. I was looking more for a tail -f script. In the end I went from a cron job.
Luminous
Op
Posts: 146 Joined: Fri Feb 12, 2010 1:00 pm
Post
by Luminous » Thu Aug 26, 2010 11:36 pm
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.
greenbear
Owner
Posts: 733 Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway
Post
by greenbear » Mon Sep 06, 2010 8:07 pm
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]"}