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 

Using 'set {my-var}' prob
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Apr 21, 2006 5:20 am    Post subject: Using 'set {my-var}' prob Reply with quote

I'm working on a rather old script for compressing logs called logzipper.tcl

Right off the top, there is a line that has:
Code:

if {[info exists {logfile-suffix}]}


It's attempting to parse the bot's global configs for the 'logfile-suffix' but the - char is acting as a arithmetic subtract and so the var is coming out as 'logfile' only. The script was written for eggdrop 1.4.

I'm curious if this behaviour is a bug, or is expected? Is there a way to work around it in a clean manner (renaming the var is obviously an option, but perhaps there are other ways to fix this without renaming.)

I've done a bit of searching on the forums and google, but have not seen any similar issues. I'm not sure what to look for beyond the phrase 'logfile-suffix'

tia
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Apr 21, 2006 5:25 am    Post subject: Reply with quote

I should have mentioned I'm using eggdrop 1.6.17.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Fri Apr 21, 2006 6:20 am    Post subject: Reply with quote

you are incorrect, there is nothing wrong with that expression

this will work too, it's equivalent to yours:
Code:

if [info exists logfile-suffix]

_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Apr 21, 2006 8:01 pm    Post subject: Reply with quote

Didn't work for me..
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Apr 22, 2006 1:45 am    Post subject: Reply with quote

rosc2112 wrote:
Didn't work for me..


maybe so, but not for the reason you think
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sat Apr 22, 2006 2:42 am    Post subject: Reply with quote

It's most likely you try to use a global var within a proc/namespace. In that case ::logfile-suffix should solve the issue.
_________________
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...
Back to top
View user's profile Send private message MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Apr 22, 2006 6:46 am    Post subject: Reply with quote

Here's a couple of test scripts I made:
Code:

# testscript 1
set myvar-fu "foo"
bind msg n testfu testfu
proc testfu { nick uhost hand text } {
global myvar-fu
puthelp "PRIVMSG $nick :$myvar-fu"
}

Code:

#testscript 2
bind msg n testfu testfu
proc testfu { nick uhost hand text } {
set myvar2-fu "foo2"
puthelp "PRIVMSG $nick :$myvar2-fu"
}

It didn't matter where the var-fu thing was, in or out of a proc. In both cases, tcl only saw "myvar" or "myvar2" and chops off the -fu Smile

test1
Tcl error [testfu]: can't read "myvar": no such variable

test2
Tcl error [testfu]: can't read "myvar2": no such variable

I've not seen any documentation that says vars cannot use a '-' char, the closest related documentation I have seen is regarding glob. I don't know if that applies to this situation.

Here is the code from logzipper.tcl which is what I'm trying to fix:
Code:

proc lz_zip { } {
 global lz lz_recipient botnick {switch-logfiles-at} {keep-all-logs}
 if {[info exists {logfile-suffix}]} {
  global {logfile-suffix} } else {
  set {logfile-suffix} ".%d%b%Y"
 }


None of the vars with - chars work, with or without curly braces..

There is also this line further along:
Code:

 if {${keep-all-logs} == 1} {
  set lz(searchstr) "*[strftime ${logfile-suffix} [expr [unixtime] - 86400]]"} else {
  set lz(searchstr) "*yesterday"
 }


I've temporarily worked around the problem by renaming the vars to not use dashes '-' and just use the values as found in the eggdrop.conf, but that's not very elegant or portable.

I'm not sure I understand what you mean by using ::var-fu , De Kus. Would you show me an example? Thanks for actually being helpful. Smile
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 22, 2006 9:08 am    Post subject: Reply with quote

If you stated your problem clearly from the 1st post then you would've solved your problem way back in this topic. Your problem is in using a variable with a '-' in it. It's simple, see this example code:
Code:
set myvar-fu "foo"

bind msg n testfu testfu

proc testfu {nick uhost hand text} {
 global myvar-fu
 if {[info exists myvar-fu]} {
  puthelp "PRIVMSG $nick :${myvar-fu}"
 }
}

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sat Apr 22, 2006 10:34 am    Post subject: Reply with quote

the issue is something else:

set var $var-var
--> reads from 'var-var'
set var "$var-var"
--> reads from 'var' and adds '-var' as string
_________________
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...
Back to top
View user's profile Send private message MSN Messenger
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Apr 22, 2006 1:35 pm    Post subject: Reply with quote

De Kus wrote:
the issue is something else:

set var $var-var
--> reads from 'var-var'
set var "$var-var"
--> reads from 'var' and adds '-var' as string


nah, these are equivalent, with the latter effect
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Apr 22, 2006 3:39 pm    Post subject: logzipper fix Reply with quote

Sir_Fz wrote:
If you stated your problem clearly from the 1st post then you would've solved your problem way back in this topic. Your problem is in using a variable with a '-' in it. It's simple, see this example code:
Code:
set myvar-fu "foo"

bind msg n testfu testfu

proc testfu {nick uhost hand text} {
 global myvar-fu
 if {[info exists myvar-fu]} {
  puthelp "PRIVMSG $nick :${myvar-fu}"
 }
}


Ok, I think I'm starting to understand how this works (not exactly sure *why* it works this way) but it seems that using myvar-fu with quotes "" changes the behavior (as in, 'set lz(searchstr) "*[strftime ${logfile-suffix} [expr [unixtime] - 86400]]"}' is the section of the original code that was producing the error.

The original script was also trying to set the global 'logfile-suffix' with 'if {[info exists logfile-suffix]}' but this didn't work at all unless I put 'logfile-suffix' into the global section anyway! Silly =)

Apparently the only real fix it needed was to add logfile-suffix to the global var declaration.. dah...

Anyway, here's my fixed version for anyone else that might find it useful:
Code:

# LogZipper             2.0 by Baerchen, May 2001
#                              for eggdrop 1.4.x+
#                       baerchen@germany-chat.net
#
# HISTORY
#
# 2.0.1-rosc    - Updated by Rosc at rosc2112.net to work with eggdrop 1.6.x (April 2006)
#               - Uses bzip2 now, I see no point in making a tarball for a single file.
#               - Added bind msg logzip to run the script manually (mainly for testing purposes)
#
# 2.0
# Baerchen      - Complete rewrite: 1.01f did not really what it was supposed
#                 to do :/
#               - Added possibility of sending various (zipped) logs
#                 to various recipients
#               - Now works with keep-all-logs set to 1
#
# 1.01f
# Baerchen      First public release
#
# CONFIGURATION

set lz(logloc) "logs/"
set lz(duration) 90
set lz(sendlogs) 0
set lz_recipient(1) "user@mail log1.log #channel1.log"

# CODEBASE BELOW

bind evnt - logfile lz_wait
proc lz_wait {logfile} {timer 1 lz_zip}
putlog "LogZipper 2.0 by Baerchen (keeping logs for $lz(duration) days)"

bind msg n logzip msg:lz_zip
proc msg:lz_zip {nick uhost hand text} {
lz_zip
}

proc lz_zip { } {
        global lz lz_recipient botnick switch-logfiles-at keep-all-logs logfile-suffix
        if {![info exists logfile-suffix]} {
# set logfile-suffix is only needed as a fall-back, in some off chance that the global var isn't found..
                set logfile-suffix ".%d-%b-%Y"
        }
        set lz(date) [strftime "%b-%d-%Y" [expr [clock seconds] - 86400]]
        set lz(max) [expr [clock seconds] - ($lz(duration) * 86400) + 60]
        set lz(filestomail) ""
        set i 0; set j 0; set k 0
        if {(${keep-all-logs} == 0) && (${switch-logfiles-at} == 2500)} {
                putlog "Logzipper: Invalid configuration: log files do not switch. You might want to correct that."
                return
        }
        if {${keep-all-logs} == 1} {
                set lz(searchstr) "*[strftime ${logfile-suffix} [expr [unixtime] - 86400]]"
        } else {
                set lz(searchstr) "*yesterday"
        }
        set lz(filelist) [glob -directory $lz(logloc) -nocomplain -- $lz(searchstr)]
        foreach e $lz(filelist) {
                if {$e == ""} {continue}
                        set f "[string range $e 0 [string last . $e]]$lz(date).bz2"
                        set lz(zerror) [catch {exec bzip2 -z $e}]
                        if {$lz(zerror)} {
                                putlog "LogZipper: An error occured while trying to zip $e"
                                continue
                        }
                set lz(ferror) [catch {file delete -force $e}]
                if {$lz(ferror)} {
                        putlog "LogZipper: An error occured while trying to delete $e"
                }
                lappend lz(filestomail) [string range $f [expr [string last / $f] +1] end]
                incr i
        }
        set lz(filelist) [glob -directory $lz(logloc) -nocomplain -- *.???-??-????.bz2]
        foreach e $lz(filelist) {
                if {$e == ""} {continue}
                if {[file mtime $e] <= $lz(max)} {
                        set lz(ferror) [catch {file delete -force $e}]
                        if {$lz(ferror)} {
                                putlog "LogZipper: An error occured while trying to delete $e"
                                continue
                        }
                        incr j
                }
        }
        set lz_status "LogZipper: zipped $i logs, deleted $j expired logs. "
        if {$lz(sendlogs)} {
                foreach e $lz(filestomail) {
                        if {$e == ""} {continue}
                        foreach el [array names lz_recipient] {
                                set rec [lindex $lz_recipient($el) 0]
                                set what [lrange $lz_recipient($el) 1 end]
                                foreach ele $what {
                                        if {[string match -nocase *$ele* $e]} {
                                                set lz(merror) [catch { exec uuencode $lz(logloc)$e $e | mail $rec }]
                                                if {$lz(merror)} {
                                                        putlog "LogZipper: An error occured while trying to uuencode or
                                                        continue
                                                }
                                                incr k
                                        }
                                } 
                        }
                }
                append lz_status "Sent $k logs via email."
        }
        putlog "$lz_status"
}
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 22, 2006 6:59 pm    Post subject: Reply with quote

Either add it to global or use ${::logfile-suffix}.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Zircon
Op


Joined: 21 Aug 2006
Posts: 191
Location: Montreal

PostPosted: Tue Feb 06, 2007 1:05 am    Post subject: Reply with quote

Hi rosc2112

I have a question about ur updated logzipper.tcl for 1.6.17. I used ur version of this script. It s zippin the file, but it doent send it coz it looks for wrong file.

I edited the script to make these settings :

set lz(logloc) "logs/quizz/culture/"
set lz(duration) 1
set lz(sendlogs) 1
set lz_recipient(1) "zircon@gmail.com culture"

and in the config file i have these :

logfile jpk #culture "logs/quizz/culture/culture"
set keep-all-logs 1
set logfile-suffix ".%Y%b%d.log"

When i make the test manually with messaging the bot with logzip, i get these messages in the party line

LogZipper: An error occured while trying to uuencode or mail culture.2007Feb04.Feb-04-2007.bz2

LogZipper: zipped 1 logs, deleted 0 expired logs. Sent 0 logs via email.

So the script made the zip of culture.2007Feb04.log to culture.2007Feb04.log.bz2 as it should be, but couldnt sent it in a mail, cause it was trying to send the file culture.2007Feb04.Feb-04-2007.bz2, which doesnt exist.

Please, do u have some idea to solve this problem, to make the script send the right file ?

Thanks in advance Smile

PSssttt : by the way, what to do to make the script leave the input file there ( the unzipped file ), and not delete it ?
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Feb 06, 2007 2:38 pm    Post subject: Reply with quote

I dont use the mail feature, sorry. Try adding debug "putcmdlog" stuff in the script to get the real error messages that came from your shell, apparently there is a problem with mail on your shell, not the script.
Back to top
View user's profile Send private message
Zircon
Op


Joined: 21 Aug 2006
Posts: 191
Location: Montreal

PostPosted: Tue Feb 06, 2007 2:50 pm    Post subject: Reply with quote

Hello rosc2112

Thanks for replying. I think that the mail feature is working, coz i receive a mail, but empty, no file attached too.

The problem is that the script is trying to send the file culture.2007Feb04.Feb-04-2007.bz2 which doesnt exist. The right file to send is culture.2007Feb04.log.bz2.

My problem is that when the script want to send the file, it adds "Feb-04-2007" at the end in the name of the right file.

Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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