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.

Script is not closing files (I think)

Old posts that have not been replied to for several years.
Locked
t
thedude0001
Voice
Posts: 7
Joined: Sat Dec 18, 2004 8:32 pm

Script is not closing files (I think)

Post by thedude0001 »

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 :)

Here's the script:

Code: Select all

# 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"
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

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
t
thedude0001
Voice
Posts: 7
Joined: Sat Dec 18, 2004 8:32 pm

Post by thedude0001 »

Well, what is a ftpd used for? I use mine for serving files...

And only the overall traffic is announced, not the traffic / user. The script just reads the different userfiles to get this data.
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

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
t
thedude0001
Voice
Posts: 7
Joined: Sat Dec 18, 2004 8:32 pm

Post by thedude0001 »

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 ;)
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Heh and we dont have to help you. I hope you enjoy learning TCL scripting. :wink:
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
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

^DooM^ wrote:What are you using the ftp for? And why do you need a public announcement of bandwidth / per user?
It's a file sharing script. I believe forum rules prevent us from assisting anyone with these type of scripts anyway.

Consigning this thread to the junkyard may be appropriate.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

that said, just add 'close $fp' after the 'set lines ....' line
t
thedude0001
Voice
Posts: 7
Joined: Sat Dec 18, 2004 8:32 pm

Post by thedude0001 »

Thanks a lot, just applied that :)
Locked