smooter Posted April 18, 2008 Share Posted April 18, 2008 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 Link to comment Share on other sites More sharing options...
Monamo Posted April 18, 2008 Share Posted April 18, 2008 (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.")EndIfWhen 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!smooterI 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:CODEIf 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 $varEndFuncEdit: Modified function to account for returning the previous year as well when "last month" happens to be December. Edited April 18, 2008 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] Link to comment Share on other sites More sharing options...
weaponx Posted April 18, 2008 Share Posted April 18, 2008 #Include <Date.au3> $result = _DateAdd('M', -1,_NowCalcDate()) $lastMonth = StringMid($result,6,2) MsgBox(0,"",$lastMonth) Link to comment Share on other sites More sharing options...
smooter Posted April 18, 2008 Author Share Posted April 18, 2008 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now