mIRC Home    About    Download    Register    News    Help

Print Thread
#172664 13/03/07 06:06 PM
Joined: Sep 2006
Posts: 43
M
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Sep 2006
Posts: 43
I asked a similar question before for monthly now this may be kinda hard but I will ask anyways

I am looking for a way to zip logs every week automatically then delete the logs in logs folder

like this
Sunday night/Monday morning at midnight I want it to zip all logs and place that zip in C:\Program Files\mIRC\LogsZip\ folder with the date as the zip name now if it could do it by log name that would be awesome ie #channame1.log all in one zip and #channame2.log in another ect.

Thank you
McOwnage
Jamie

Last edited by McOwnage; 13/03/07 06:10 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
All you need is a timer that goes off every night at midnight and checks the day of the week and if it's Monday (Sunday night), then it runs a command line zip program and deletes the logs.

Code:
/timer 0:00 0 30 if ($date(ddd) == Mon) { ZipLogs }

alias ZipLogs {
  pkzip logs\#channel1*.log LogsZip\#channel1.log
  pkzip logs\#channel2*.log LogsZip\#channel2.log
  pkzip logs\#channel3*.log LogsZip\#channel3.log
  .timer 1 60 .remove logs\*.log
}


(Put the timer in an on START event or some other place)

Of course, this requires that you hardcode all of the channels you are logging.

As a note, you may want to include the date in the ZIP filename. Also, this requires pkzip.exe to be present. You could also use WinZip or WinRAR, but you'll need to find out the appropriate command line for those.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Couple of suggestions

1. The logging directory may not be <mircdir>\logs, you should use $logdir for that ideally.

2. /remove doesn't support wildcards, you'd have to use $findfile() or some other way of looping through logs (or use "DOS" commands, like del).

3. Unconditionally removing logs after 1 minute is not safe. You should be checking whether the logs were zipped up and stored in LogsZip\ first (you can't assume the operation will always be successful, even if you are 100% certain your script is correct).

4. There is no need for a timer that fires every 30 secs (I know, it's a simple $date() check but it just doesn't feel right). I would use something like this for the timer part:
alias zipLogsTimer .timerZipLogs -io 00:00 1 60 zipLogsTimer $(|) if ($date(ddd) == Mon) zipLogs
(60 is there so that the timer fires at 00:01, so the new timer created by the old one starts at 00:00 of the *next* day)

Edit: added -io switches in /timer, I should've followed my own advice.

Last edited by qwerty; 22/03/07 09:02 PM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Question, you use pkzip.exe as a solution. Is there a way I can do this using WinXP's compressed file support?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Heh. I did that up quickly before leaving for work. I agree that $logdir is preferable. I also forgot that /remove doesn't accept wildcards. I did debate about the timeframe for removing the logs. I was meaning it to be an example of how to do it and not the final product, but I didn't really point that out and considering how often I give a final product, I really should have.

Now, I don't work with date timers and haven't really done much with them. If you set a timer for a specific time of day, it doesn't need to check it at that time? You just need to trigger it and it will work? /timer 0:00 1 1 echo -a Midnight for example? Thinking back about the example for the /timer command (I don't have it in front of me right now), I seem to remember that being how it showed it. I guess I assumed that you needed the timer to check every minute to see if it was that time... kind of like: /timer 0 60 if ($time(hh:nn) == 0:00) { do this } ... obviously I was wrong and I'll keep that in mind if I use a time again.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
As I mentioned, you can use anything that has a command line interface. I used that method because that's what I prefer. If you can find a description of how to zip something from the command line with XP's internal ZIP'er, than go ahead and use that.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard