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.

tail -f (filename)

Old posts that have not been replied to for several years.
w
wize_one

tail -f (filename)

Post by wize_one »

was wondering if there is a way to put the bot in one room and have it paste the contents of a file that is always updating. any help or pointers in the right direct would be a great help.

thanks for your time.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

if [file readable $file] {
  set fc [open "|tail -f $file"]
  fconfigure $fc -blocking 0
  fileevent $fc readable {puthelp "privmsg $chan :[gets $fc]"}
}
w
wize_one

Post by wize_one »

doesnt seem to work..8(

Code: Select all

bind pub - #watch my_watch
proc my_watch {nick uhost handle channel arg} {

if [file readable /var/log/httpd/error_log] {
  set fc [open "|tail -f /var/log/httpd/error_log"]
  fconfigure $fc -blocking 0
  fileevent $fc readable {putserv "privmsg $nick :[gets $fc]"}
}
  return 1
}
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

wize_one wrote:doesnt seem to work..8(

[/code]
it works for me

explain what did you do, exactly
w
wize_one

Post by wize_one »

put that code in one of my tcl scripts, rehashed the bot, did #watch, went to the website and entered a fake url(so it would add to the error log) went back to chat and there was nothing there
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

nick and fc need to be global
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

hey quit msg'ing me already and make your fileevent script vars (nick and fc) global; if you could manage to write a proc, you surely know what 'global' is
P
Porch
Voice
Posts: 4
Joined: Sun Apr 17, 2005 3:12 am

Post by Porch »

Can someone post the full version of this? I really need to tail a file and I don't know enough tcl to make the below script work. I spent 2 hours looking over the docs and trying stuff with no luck.

Thanks a bunch.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Part of the ultimate story "The Manual":
http://www.tcl.tk/man/tcl8.4/TclCmd/global.htm
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
P
Porch
Voice
Posts: 4
Joined: Sun Apr 17, 2005 3:12 am

Post by Porch »

I am putting it in the wrong spot? I get this error.




[03:38] Tcl error [my_watch]: variable "nick" already exists



Code: Select all




bind pub - watch my_watch



proc my_watch {nick uhost handle channnel arg} {



    global nick fc



    if [file readable /home/et/1] {

	set fc [open "|tail -f /home/et/1"]

	fconfigure $fc -blocking 0

	fileevent $fc readable {putserv "privmsg $nick :[gets $fc]"}

    }



return 1

}

User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Porch wrote:proc my_watch {nick uhost handle channnel arg} {
you need to rename this "nick" to something else (like cnick) and everywhere THIS nick is meant and not the global nick.
alternatively you can use $::nick referance the global nick and leave nick like it is, remember to remove "nick" from the global line in the 2nd case.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
P
Porch
Voice
Posts: 4
Joined: Sun Apr 17, 2005 3:12 am

Post by Porch »

Well, I understand the words, but the golbal NICK and a local nick? I don't have a clue what you are saying to do.

I mucked around with it and hard coded the vars into it. That seems to work. For now.

Thanks
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

i would suggest not to use tail -f cause that doesn't work, all the time, ive seen that after running tail-f durring a perriod of time that it just quits tailing

maybe try this

get the size of the file

=> get file size filename

compare to previous size if greater open file seek to the buffer offset and read, .. if smaller then go to the previous file for instance

syslog => syslog.0 syslog.1 ...

do the same set the offset using seek and read then move on to the current , now append the number of read bytes to the current file size


quick:

1024 < old
2049 < new
read file 1025
close file
set newfilesize 2049

loop back to step one
Last edited by Ofloo on Sun Apr 17, 2005 4:59 pm, edited 1 time in total.
XplaiN but think of me as stupid
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

you need to understand, that each var is assinged to a specific procedure or namespace. if you create a var in the top level (outside of any proc) it is called a "global" var, or you could say it belongs to the namespace of emtpy string (namespace references use namespacename::var, so if namespacename is an emtpy string it will ::var). If you define a proc with parameters like nick uhost hand chan etc. these var will only be valid within that proc and will not be permanent, means, they will be newly created each time the proc is called.
So if you try to "include" the global var "nick" while you have already a var called "nick" within that proc, you will encounter problems, because you try to have 2 vars with one and the same name which logically is impossible ;).

So I suggested 2 diffrent solutions:

1st: rename the temporar var "nick" belonging to the proc
ex.: proc my_watch {cnick uhost handle channnel arg} { global nick; ... }

2nd: don't include the global var "nick" into the proc and refer it direct via its namespace (::nick).
ex.: proc my_watch {nick uhost handle channnel arg} { ...; putserv "$::nick" }
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
C
CtrlAltDel
Halfop
Posts: 49
Joined: Wed Jun 02, 2004 7:58 am

Post by CtrlAltDel »

Porch wrote:proc my_watch {nick uhost handle channnel arg}
Just wondering, is this how it is in the script?
Locked