egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scan log for changes and process (events)

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
supersam
Voice


Joined: 25 Aug 2010
Posts: 2

PostPosted: Wed Aug 25, 2010 4:43 pm    Post subject: Scan log for changes and process (events) Reply with quote

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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Wed Aug 25, 2010 8:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
supersam
Voice


Joined: 25 Aug 2010
Posts: 2

PostPosted: Thu Aug 26, 2010 2:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Thu Aug 26, 2010 11:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
greenbear
Owner


Joined: 24 Sep 2001
Posts: 733
Location: Norway

PostPosted: Mon Sep 06, 2010 8:07 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber