Page 1 of 1 1
Topic Options
#141938 - 2005-06-17 07:27 PM What's wrong with this code? Trying to delete certain files...
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
I have a script that is harvesting event logs and importing them into a SQL database. We have 15 Domain Controllers, and 2500 users - so the sheer amount of .evt files that are hanging around is huge.

When the files are copied to a central server, they are stamped like this:
Code:

SERVERNAME-20050617-131101-SECURITY.LOG
Server - YYYYDDMM - HHMMSS - Event Log



So I wrote something that converts today's date to that format, and is supposed to look for files in that folder that DO NOT contain that string, and delete them.

It looked like it worked the first time I ran it, but it could just be the lag in explorer while I was viewing the folder as it was about 13GB...Now, all the files are gone, as well as a file that was not an .evt file - none of this is what I expected to happen.

Here is my code:
Code:

$PATH = "\\hqweb1\Server Admin Group\Documentation\Server Admin Documentation\Server Event Logs\SecurityLogs"
$TODAY = Split(@DATE,"/",)
$TODAY = Join($TODAY,"",)
$Files = Dir("$PATH\*.evt")
While $Files <> "" and @ERROR = 0
$Files = Dir()
If not InStr($Files,$TODAY)
Del "$PATH\$Files"
EndIf
Loop



Maybe someone could explain it to me and possibly re-arrange it for me.

Thanks!
_________________________
-- oobnuker - .KIX hack - no really.

Top
#141939 - 2005-06-17 07:38 PM Re: What's wrong with this code? Trying to delete certain files...
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
Nevermind...
I figured it out:
Code:

$PATH = "c:\test"
$TODAY = Split(@DATE,"/",)
$TODAY = Join($TODAY,"",)
$Files = Dir("$PATH\*.txt")
While $Files <> "" and @ERROR = 0
$TODAYSFILE = InStr($Files,$TODAY)
If $TODAYSFILE = 0
Del "$PATH\$Files"
EndIf
$Files = Dir()
Loop


Works well for me.
_________________________
-- oobnuker - .KIX hack - no really.

Top
#141940 - 2005-06-19 07:44 PM Re: What's wrong with this code? Trying to delete certain files...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You could use a combination of ReadEventlog() and DBCommand() to transfer select events directly into a database.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2375 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.178 seconds in which 0.152 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org