<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/18808" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2012-01-31T01:14:52-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/18808</id>

		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-31T01:14:52-04:00</updated>

		<published>2012-01-31T01:14:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98650#p98650</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98650#p98650"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98650#p98650"><![CDATA[
Never mind. I just load the script and have it do:<br><div class="codebox"><p>Code: </p><pre><code>proc evnt:init_server {type} {        logMonitorOpenFile $::logMonitorFilename}</code></pre></div>Thanks again for all your help NML! <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Tue Jan 31, 2012 1:14 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-30T21:17:09-04:00</updated>

		<published>2012-01-30T21:17:09-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98649#p98649</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98649#p98649"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98649#p98649"><![CDATA[
Ok Nml. Thank you.<br><br>Whats the best way to make sure that this "log monitoring" starts as soon as the bot is started?<br><br><br>KenH83.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Mon Jan 30, 2012 9:17 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2012-01-30T03:19:56-04:00</updated>

		<published>2012-01-30T03:19:56-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98642#p98642</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98642#p98642"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98642#p98642"><![CDATA[
When using the .tcl-command, don't use those brackets. "openFile" does not return anything that's supposed to be executed as a command.<br><br>Just use <div class="codebox"><p>Code: </p><pre><code>.tcl openFile thefile</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Mon Jan 30, 2012 3:19 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-29T20:43:10-04:00</updated>

		<published>2012-01-29T20:43:10-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98641#p98641</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98641#p98641"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98641#p98641"><![CDATA[
nml,<br><br>I changed the following line:<div class="codebox"><p>Code: </p><pre><code>puts stdout "Read line: $::tailBuffer($fileId)"</code></pre></div>to: <div class="codebox"><p>Code: </p><pre><code>putlog "Read line: $::tailBuffer($fileId)"</code></pre></div>from partyline on the bot i execute the following command:<div class="codebox"><p>Code: </p><pre><code>.tcl [openFile /path/to/filename.log]</code></pre></div>The actual log file i'm using is 100% real the user account the bot is running under has full read access to the log file and works fine from ssh console when i do something like: tail -f /path/to/filename.log<br><br>When I execute the above command on the partyline of the bot the output is the following:<div class="codebox"><p>Code: </p><pre><code>Tcl error: invalid command name "after#0"</code></pre></div>nml .. I know I've said it before, but thank you very much for all the time you've taken to address this script. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>EDIT: It does start reading the log file.. but how can I get rid of that initial error. <br><br>Lastly whats the best way to start this openFile proc when the bot is first started?<br>- KenH83<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Sun Jan 29, 2012 8:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2012-01-29T16:50:33-04:00</updated>

		<published>2012-01-29T16:50:33-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98640#p98640</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98640#p98640"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98640#p98640"><![CDATA[
You call "openFile" to open and start monitoring a file. Yes, it will continue to check the file roughly once every second for new content - assuming there's no error condition within "readFile" (in it's current state, there isn't much that could cause an error to occur).<br><br>Obviously, you'll have to modify "readFile" to implement whatever parsing you've set your mind to (I simply had the script write the read line to stdout for demonstration purposes).<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sun Jan 29, 2012 4:50 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-29T16:07:20-04:00</updated>

		<published>2012-01-29T16:07:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98639#p98639</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98639#p98639"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98639#p98639"><![CDATA[
nml, whats the proper syntax to get this started.. and it stays running right?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Sun Jan 29, 2012 4:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2012-01-29T14:06:42-04:00</updated>

		<published>2012-01-29T14:06:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98636#p98636</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98636#p98636"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98636#p98636"><![CDATA[
Or actually, scrap that..<br>The file will always be considered readable once it reaches the end of file, resulting in the event being triggered over and over (blocking eggdrop).<br><br>There are a few recipes for doing this using timers though; the following code tries to read one line every second (with some modifications, it could be made to try and read as many lines as possible once every second ).<div class="codebox"><p>Code: </p><pre><code>proc readFile {fileId} {  #(Try to) read one line  set bytes [gets $fileId line]  if {$bytes &gt;= 0} {    #We've got some data, append it to the buffer.    append ::tailBuffer($fileId) $line    if {![eof $fileId]} {      #Verify that we got a line with EOL; do something intelligent with the line of text      puts stdout "Read line: $::tailBuffer($fileId)"      #Clear the buffer..      set ::tailBuffer($fileId) ""    }  }  #Start another 1000 ms timer to call readFile again  after 1000 [list readFile $fileId]}proc openFile {file} {  #open file for read-only access  set fileId [open $file RDONLY]  #Move to the end of the file after opening, optional:  seek $fileId 0 end  #Configure the file for non-blocking access  fconfigure $fileId -blocking 0  #Prepare a buffer for lines missing EOL  set ::tailBuffer($fileId) ""  #Start a 1000 ms timer to call readFile  after 1000 [list readFile $fileId]}</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sun Jan 29, 2012 2:06 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2012-01-28T19:20:55-04:00</updated>

		<published>2012-01-28T19:20:55-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98634#p98634</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98634#p98634"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98634#p98634"><![CDATA[
Well, as I said, this is asynchronous IO. Which means the code is event-driven and non-blocking by nature. You simply call the openFile proc once to open the file and set up the fileevent, and the event engine will call the readFile proc with appropriate arguments whenever there is something readable within the file.<br><br>That said, I do now notice that I wrote the code for socket communications, where eof would indicate that the socket had been closed. For a "tail-like" behavior, the readFile proc would be re-written like below:<div class="codebox"><p>Code: </p><pre><code>proc readFile {file} {  if {[gets $file line] &gt;= 0} {    #gets returned a complete line from the file, do some further processing    puthelp "PRIVMSG #somechannel :Read \"$line\" from logfile"  }}</code></pre></div>Also, I should'nt use // for comments in tcl...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sat Jan 28, 2012 7:20 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-28T16:19:42-04:00</updated>

		<published>2012-01-28T16:19:42-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98632#p98632</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98632#p98632"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98632#p98632"><![CDATA[
I guess what I'm getting at here, is I want to actively monitor a log file so that each time something new is wrote the tcl script catches it.. but doesn't care about previous entries..<br><br>and.. the log file must remain intact like a normal log file.<br><br><br><br>Hopefully I'm not confusing you or asking too much, as I really do appreciate your offerings here. You're very kind!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Sat Jan 28, 2012 4:19 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-28T16:17:32-04:00</updated>

		<published>2012-01-28T16:17:32-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98631#p98631</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98631#p98631"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98631#p98631"><![CDATA[
How can I safely start this and allow it to keep running so it actively checks the files.. without it interferring or 'locking' up the bot?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Sat Jan 28, 2012 4:17 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2012-01-28T13:17:29-04:00</updated>

		<published>2012-01-28T13:17:29-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98630#p98630</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98630#p98630"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98630#p98630"><![CDATA[
Roger that,<br>Then you'll need to use asynchronous IO:<div class="codebox"><p>Code: </p><pre><code>proc openFile {file} {  set fd [open $file "RDONLY"]  fconfigure $fd -blocking 0  fileevent $fd readable [list readFile $fd]}proc readFile {file} {  if {[eof $file]} {    close $file  } else {    gets $file line    //Do something with $line    puthelp "PRIVMSG #somechannel :Read \"$line\" from log"  }}</code></pre></div>openFile is used to open the file and set up the file-events. readFile will then be called by the event whenever there is a new line to be read in the (opened) file.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sat Jan 28, 2012 1:17 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-28T11:19:58-04:00</updated>

		<published>2012-01-28T11:19:58-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98628#p98628</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98628#p98628"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98628#p98628"><![CDATA[
nml,<br><br>Yeah.. i'm looking for example on how to do it for a system log file.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Sat Jan 28, 2012 11:19 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2012-01-28T10:29:54-04:00</updated>

		<published>2012-01-28T10:29:54-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98626#p98626</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98626#p98626"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98626#p98626"><![CDATA[
With the 1.6.20 version, the LOG binding was introduced. This binding can be set up to trigger on any log-message matching the given "channel text" pattern:<div class="codebox"><p>Code: </p><pre><code>    (47) LOG (stackable)         bind log &lt;flags&gt; &lt;mask&gt; &lt;proc&gt;         proc-name &lt;level&gt; &lt;channel&gt; &lt;message&gt;         Description: triggered whenever a message is sent to a log. The mask is           matched against "channel text".           The level argument to the proc will contain the level(s) the message           is sent to, or '*' if the message is sent to all log levels at once.           If the message wasn't sent to a specific channel, channel will be set           to '*'.         Module: core</code></pre></div>A very simple example would be as follows:<div class="codebox"><p>Code: </p><pre><code>proc parseLog {level channel message} {  puthelp "PRIVMSG #thechannel : Received log message \"$message\" from \"$channel\" ($level)"}bind log - "*" parseLog</code></pre></div>If you'd rather observe a given file on the filesystem (not necessarily generated by your eggdrop), you'd have to resort to asynchronous file IO using the fileevent mechanism in tcl.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Sat Jan 28, 2012 10:29 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[kenh83]]></name></author>
		<updated>2012-01-27T23:08:43-04:00</updated>

		<published>2012-01-27T23:08:43-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=98625#p98625</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=98625#p98625"/>
		<title type="html"><![CDATA[Log Monitor]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=98625#p98625"><![CDATA[
I would love to have a script that I could use to parse log files "live".<br><br><br>I'm not even sure where to really start with how to read a log file basically every second and have it return the new lines of text that are put into the log file. <br><br>As far as parsing the text, I can handle that much.. I just dont know how to get the first part.<br><br><br>Thanks so very much in advance!<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11350">kenh83</a> — Fri Jan 27, 2012 11:08 pm</p><hr />
]]></content>
	</entry>
	</feed>
