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.

Bot stops logging when erasing the log file

General support and discussion of Eggdrop bots.
Post Reply
C
Car`a`carn
Voice
Posts: 5
Joined: Sun Apr 01, 2007 6:29 pm

Bot stops logging when erasing the log file

Post by Car`a`carn »

I've a little problem where my bot is logging a channel and I have it keeping all the logs from everyday. Now it's so that I want the logs to be removed the 1st every month. So good and well I set a crontab to delete all log files in the log directory 1min after midnight, which worked nicely. The problem with this is that the current log (e.g. channel.log20070401) the bot was using was deleted as well. I knew of this of course but figured it wasn't a problem since the bot would re-create the file and keep logging from a minute past midnight on the first and until the next month.

As it seem the bot didn't write at all and it didn't even re-create the todays file at all. Doing a rehash didn't help either so I had to comment out the log-row in the conf file and rehash and then reverse it and rehash again for it to re-create it and continue logging.

So my question is. Shouldn't the bot see that the todays (current) file it was writing the logs to is missing and re-create it and keep storing the conversations in the logs. I guess I could solve my refresh the logs every month problem with a number of crontabs but wondering if there is a way to get the bot to rec-reate the log file if being erased?
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Try restarting the bot.

Do some forum searching and you should find further topics covering varying aspects of your post.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I have a faint memory that eggdrop does not close logfiles once created/opened, until it rotates logs. Hence you'd get the situation you've described if you delete the file while it's still opened.
NML_375
C
Car`a`carn
Voice
Posts: 5
Joined: Sun Apr 01, 2007 6:29 pm

Post by Car`a`carn »

Alchera: I believe I also tried to restart the bot with no success, can't swear on it but would like to find a solution without having to restart it :). I have searched the forum a lot with no luck.

nml375: Yes it creates the file when a new day starts but the file that I erased was never re-created of course.

Thanks for the replies :).
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Copy the file to a different name for your backup, then do 'echo > original-filename' to wipe out the contents of the original. That should do the trick. Either that or look at the log zipper tcl, which will make archives for every day and delete old archives every xx days..

http://members.dandy.net/~fbn/logzipper.tcl.txt
C
Car`a`carn
Voice
Posts: 5
Joined: Sun Apr 01, 2007 6:29 pm

Post by Car`a`carn »

rosc2112: Yeah I have been pondering of doing something like the first one you said. Would mean more crontabs though but seems as if there is no other way right now. Thanks.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@Car`a`carn:
Indeed it is not, as eggdrop never closed the file. Hence, the next logentry will use the already opened filehandle instead doing another call to open (and thus not creating a new file).

One way of doing it would be using the evnt-binding to trigger on log-rotation, and have a script delete each file (after testing that it's not today's logfile). Something like this, I guess (code has'nt been tested, and assumes there's only logfiles in ./logs/):

Code: Select all

bind - evnt "logfile" clearlogs
proc clearlogs {event} {
 if {[clock format [clock seconds] -format "%e"] != 1} {
  return
 }
 set match "*[clock format [clock seconds] -format ".log%Y%m%d"]"
 foreach file [glob "./logs/*"] {
  if {[string match $match $file]} {continue}
  file delete -- $file
 }
}
NML_375
C
Car`a`carn
Voice
Posts: 5
Joined: Sun Apr 01, 2007 6:29 pm

Post by Car`a`carn »

nml375: I'll look into it and do some experiments. Thanks :).
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Car`a`carn wrote:rosc2112: Yeah I have been pondering of doing something like the first one you said. Would mean more crontabs though but seems as if there is no other way right now. Thanks.
No need for multiple crontabs, you can either seperate commands within your single crontab line with semi-colons, or even easier, make a little shell script then invoke that from cron.
C
Car`a`carn
Voice
Posts: 5
Joined: Sun Apr 01, 2007 6:29 pm

Post by Car`a`carn »

rosc2112: Yes but since I will need to remove all files without the current one, the name will variate depending on the month I need to run different commands through crontabs (or a script) to trigger on different dates :).
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

That's why god created /bin/date, so you can distinguish filenames with dates :)
Post Reply