I've got a lovely little script here that announces the ammount of traffic produced on a glftpd server running on the same machine. Now the time-based announcement was added later and not present in the original script. The script works fine for several days, then it starts telling me that 0.0GB traffic were used this month. Taking a look at the logfile (after enabling some debug lines in the script) I see this:
[02:00] /glftpd/ftp-data/users/dude
[02:00] glftpd-traffic.tcl: couldn't open "/glftpd/ftp-data/users/dude": too many open files
Taking a closer look at the script it looks to me that the user files are never closed, only opened when the script wants to read the data, and after some days there are 1024 files open (the ulimit on this box) and no new files can be opened. My problem is that I have no big knowledge of TCL and don't know where and how I should close those files, so any help would be greatly appreciated
# v-1.05 22 Feb 05 (21:06:58)
# Don't know who the original author is, but I'm releasing this
# out with a few fixes to get around looping into negatives above
# 2GB when reading k size. -Genocaust
# glftpd users directory
set glftpdusers "/glftpd/ftp-data/users"
# output themes
# variables:
# $traffick - traffic in kilobytes
# $trafficm - traffic in megabytes
# $trafficg - traffic in gigabytes
# $msgtag - i just prepend to the outputs to match my bot theme
set msgtag "\002Alcatraz\002 :: \[\002stats \002\]"
set gtoutput(all) {$msgtag \002${trafficg}\002GB have passed through Alcatraz.}
set gtoutput(month) {$msgtag While passing through Alcatraz, \002${trafficg}\002GB had an out of body experience this month.}
set gtoutput(wk) {$msgtag \002${trafficg}\002GB saw Elvis this week in Alcatraz.}
set gtoutput(day) {$msgtag Today \002${trafficg}\002GB all agreed that 'if the dick don't fit, you must acquit.'}
# trigger
set gtcommand "!traffic"
# usage is: trigger [day/wk/month/all] - if not period is specified the default will be used
set gtdefault "month"
#regular announces
bind time - "00 00 * * *" gtgltraffic:t
bind time - "00 02 * * *" gtgltraffic:t
bind time - "00 04 * * *" gtgltraffic:t
bind time - "00 06 * * *" gtgltraffic:t
bind time - "00 08 * * *" gtgltraffic:t
bind time - "00 10 * * *" gtgltraffic:t
bind time - "00 12 * * *" gtgltraffic:t
bind time - "00 14 * * *" gtgltraffic:t
bind time - "00 16 * * *" gtgltraffic:t
bind time - "00 18 * * *" gtgltraffic:t
bind time - "00 20 * * *" gtgltraffic:t
bind time - "00 22 * * *" gtgltraffic:t
proc gtgltraffic:t {min h d m y} {
gtgltraffic {} {} {} #Alcatraz {}
return 0
}
proc gtgltraffic {nick host hand chan arg} {
set monthup 0
set monthdn 0
global msgtag
if {[llength [split $arg]]==0} {
set period $::gtdefault
} else {
set period [lindex $arg 0]
}
if {![info exists ::gtoutput($period)]} {
puthelp "PRIVMSG $chan :usage: $::gtcommand \[day/wk/month/all\]"
return
}
foreach user [glob -nocomplain $::glftpdusers/*] {
putlog $user
if {[catch {open $user} fp]} {
putlog "glftpd-traffic.tcl: $fp :("
continue
}
set lines [split [read $fp] \n]
foreach line $lines {
if {[lindex [split $line] 0]=="[string toupper $period]UP"} {
putlog $line
foreach {files size time} [lrange [split $line] 1 end] {
if {$size==""} {continue}
incr monthup $size
}
} elseif {[lindex [split $line] 0]=="[string toupper $period]DN"} {
putlog $line
foreach {files size time} [lrange [split $line] 1 end] {
if {$size==""} {continue}
incr monthdn $size
}
}
}
}
set traffick [expr wide($monthdn) + wide($monthup)]
set trafficm [format %.1f [expr wide($traffick) /1024.0]]
set trafficg [format %.1f [expr wide($trafficm) /1024.0]]
puthelp "PRIVMSG $chan :[subst -nocommands $::gtoutput($period)]"
}
bind pub - $gtcommand gtgltraffic
putlog "glFTPD Traffic 1.05 loaded"
What are you using the ftp for? And why do you need a public announcement of bandwidth / per user?
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
It all depends on the type of files you are serving.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
Well, in my world a ftpd is used for serving files, no matter what kind of files these are... And if you want to know what files I am serving and who has access to this ftpd or what color my underwear has the answer is quite simple: That's none of your damn business
Heh and we dont have to help you. I hope you enjoy learning TCL scripting.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born