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.

Need Help with tcl script Please

Old posts that have not been replied to for several years.
Locked
H
Happ

Post by Happ »

I need this script to work desperately. My shell keeps killing my trivia bot. Only way to prevent that is to delete files every few hours. Script is below, Any help would be most appreciated :smile:))
#file deletion script by Happ version 1.0
#
#
#
#time in minutes to auto delete files
set timer "120"
#directory files are in
set del_path "/usr/home/botdoc/testbot/AlreadyAsked"
#files in directory to delete
set del_files "AlreadyAskedAnimals1.qst AlreadyAskedDemoBank.qst AlreadyAskedMixed1.qst AlreadyAskedScrambleWords1.qst AlreadyAskedmusic1.qst AlreadyAskedquest2.qst AlreadyAskedquest3.qst AlreadyAskedtvmovie.qst"
#binds
bind dcc x remfiles rf_files
########begin script##################
$timer rf_files
#proc
proc rf_files {hand idx arg} {
global del_path del_files
{exec rm $del_files}
return 0
}
M
Mordred

Post by Mordred »

Try soemthing like this. It executes on startup and every 120 minutes after that.

#time in minutes to auto delete files
set del_timer "120"
#directory files are in
set del_path "lists"
#files in directory to delete
set del_files "test1.txt test2.txt test3.txt test4.txt"

proc rf_files {} {
global del_path del_files del_timer
set a [split $del_files]
foreach b $a {
file delete $del_path/$b
}
timer $del_timer rf_files
return 0
}

if {![info exists rf_files_running]} {
rf_files
set rf_files_running 1
}

Of course, change the files and path to your stuff.

Oh and beware, as you'll see in the code, it's expecting a $del_path without a trailing /

<font size=-1>[ This Message was edited by: Mordred on 2002-04-03 22:36 ]</font>
H
Happ

Post by Happ »

Many Thanks Mordred :smile:
I had to change the "120" to "5" dang shell!!
I kept checking the directory and there is at no time more then 2 or 3 alreadyasked* files in there and the ps -x command shows acceptable cpu/memory usage now.
I gave you full credit for the script in the header and the putlog
"File Deletion Version 1.0 by Mordred"
putlog "File Deletion 1.0 by Mordred loaded"
one question, is it possible to make it log or show in dcc chat that its working without constantly checking the shell?
Thanks again Mordred :smile:
M
Mordred

Post by Mordred »

Thanks for the comments. Unfortunately the file delete command doesnt return a value. The way around it is to do a check on the file status before deleting:

proc rf_files {} {
global del_path del_files del_timer
set a [split $del_files]
foreach b $a {
set found 0
set file $del_path/$b
if {[file exists $file]} {
set found 1
}
file delete $file
if {(![file exists $file]) && ($found)} {
putlog "$file deleted"
}
}
timer $del_timer rf_files
return 0
}


That will check if the file exists before deleting, and then after deleting if the file now doesnt exist and yet it did previously, print a message.
The putlog could be easily be a dccbroadcast.

<font size=-1>[ This Message was edited by: Mordred on 2002-04-04 17:18 ]</font>
Locked