Sign in to follow this  
Followers 0
smooter

Log Maintenance Date Format issues...

4 posts in this topic

Hello all,

I am trying to configure an AutoIT script to help me maintain my IIS Logfiles (and a multitude of others once I get it working), and I am having some trouble.

The issue is that I rotate a few of my web servers on a monthly basis, so I want to find and zip them up so they don't take up so much space.

The Zipping issue is solved, now I am trying to figure out how to get AutoIt to find last months logfile. I think I am on the right path, but I am not quite there.

This is what I want to do:

$sArchive = ("q:\LogFiles\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) -1 '.zip')

$sFiles = ("q:\LogFiles\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) -1 '.log')

#include "c:\include\SevenZip.au3"

if FileExists("q:\LogFiles\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) -1 & '.log' Then Then _SevenZipAdd($sArchive, $sFiles, 6, "zip")

But it doesn't work because it is actually looking for a file with "exyym.log" format when it needs to look for "exyymm.log"

But if I do this it finds the current file:

If FileExists("e:\weblogs\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) & '.log') Then

MsgBox(4096, "", "Logfile Exists.")

Else

MsgBox(4096,"", "Logfile does not Exist.")

EndIf

When I add the "-1" after the @MON it does set the month back to last month, but it converts it to a single character (If it is a single digit month obviously) which won't work.

I think it has to do with where I am putting the "-1" but it doesn't make much sense.

Thanks for your help!

smooter

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello all,

I am trying to configure an AutoIT script to help me maintain my IIS Logfiles (and a multitude of others once I get it working), and I am having some trouble.

The issue is that I rotate a few of my web servers on a monthly basis, so I want to find and zip them up so they don't take up so much space.

The Zipping issue is solved, now I am trying to figure out how to get AutoIt to find last months logfile. I think I am on the right path, but I am not quite there.

This is what I want to do:

$sArchive = ("q:\LogFiles\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) -1 '.zip')

$sFiles = ("q:\LogFiles\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) -1 '.log')

#include "c:\include\SevenZip.au3"

if FileExists("q:\LogFiles\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) -1 & '.log' Then Then _SevenZipAdd($sArchive, $sFiles, 6, "zip")

But it doesn't work because it is actually looking for a file with "exyym.log" format when it needs to look for "exyymm.log"

But if I do this it finds the current file:

If FileExists("e:\weblogs\W3SVC1\ex" & StringMid(@YEAR & @MON, 3) & '.log') Then

MsgBox(4096, "", "Logfile Exists.")

Else

MsgBox(4096,"", "Logfile does not Exist.")

EndIf

When I add the "-1" after the @MON it does set the month back to last month, but it converts it to a single character (If it is a single digit month obviously) which won't work.

I think it has to do with where I am putting the "-1" but it doesn't make much sense.

Thanks for your help!

smooter

I haven't trolled through all of the functions in Date.au3, so this might already be covered. Here's a line modification and a new function addition that should help:

CODE

If FileExists("q:\LogFiles\W3SVC1\ex" & StringMid(_LastMonth(), 3) & '.log' Then Then _SevenZipAdd($sArchive, $sFiles, 6, "zip")

Func _LastMonth()

Local $var

Select

Case @MON > 1

$var = @MON - 1

If StringLen($var) = 1 Then

$var = "0" & $var

EndIf

$var = @YEAR &$var

Case Else

$var = (@YEAR-1) & "12"

EndSelect

Return $var

EndFunc

Edit: Modified function to account for returning the previous year as well when "last month" happens to be December.

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Yepper, that did it!

I get better and better all the time with this stuff, but it is humbling to see just how far behind I am!

Thanks for all the help!

smooter

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0