Saleem
(Hey THIS is FUN)
2003-09-27 10:49 AM
Enumerate remote files

basically I want to delet old event log in all my servers centraly by running a script, I have written a script for that but it seems it is not enumerating files in remote servers.
code:
$dt1=@date
$x1 = SubStr($dt1, Len($dt1) - 9, 4)
$x2 = SubStr($dt1, Len($dt1) - 4, 2)
$x3 = SubStr($dt1, Len($dt1) - 1, 2)
$result=$x1 + $x2 + $x3
? $result
$sub=Val($result)
$sub1=$sub-7
? $sub1

$dr=Dir("\\server\eventlog")
While $dr <> "" AND @error = 0

$dt=GetFileTime ("\\server\eventlog\$dr")
? $dt
$dttrm=Left("$dt",10)
$y1 = SubStr($dttrm, Len($dttrm) - 9, 4)
$y2 = SubStr($dttrm, Len($dttrm) - 4, 2)
$y3 = SubStr($dttrm, Len($dttrm) - 1, 2)
$result1=$y1 + $y2 + $y3
? $result1

If ($result1 < $sub1)
Del "\\server\eventlog\$dr"
? "less than 7 exist"
EndIf
$DR=Dir()
Loop

any better idea to do this ??


Les
(KiX Master)
2003-09-27 11:27 AM
Re: Enumerate remote files

You don't provide enough information. Depending on what sort of eventlog you are dealing with can make a difference. Most eventlogs take care of themselves and should never be deleted. Also, most eventlogs are in constant use and so GetFileTime() will not work. Here is a script to demonstrate that.
code:
Break on
$BasePath = "%windir%\system32\config\"
$strFile = "appevent.evt","secevent.evt","sysevent.evt"
For each $element in $strFile
GetAllFileProperties($BasePath+$element)
Next
get $_

For each $element in $strFile
? $BasePath + $element + " size = "
GetFileSize($BasePath + $element)
? $BasePath + $element + " time = "
GetFileTime($BasePath + $element)
Next
get $_

Function GetAllFileProperties($FileName)
$fso = CreateObject("Scripting.FileSystemObject")
$objFile = $fso.GetFile($FileName)
? "Date created: " + $objFile.DateCreated
? "Date last accessed: " + $objFile.DateLastAccessed
? "Date last modified: " + $objFile.DateLastModified
? "Drive: " + $objFile.Drive
? "Name: " + $objFile.Name
? "Parent folder: " + $objFile.ParentFolder
? "Path: " + $objFile.Path
? "Short name: " + $objFile.ShortName
? "Short path: " + $objFile.ShortPath
? "Size: " + $objFile.Size
? "Type: " + $objFile.Type
EndFunction



Saleem
(Hey THIS is FUN)
2003-09-27 11:37 AM
Re: Enumerate remote files

i want to delete event log files which is older than 7 days, I shared event log directory as \\server\eventlog now I am trying to get the file date of each file inside the directory and if it is more than 7 days old of current date delete it.

I hope I made it clear now.


Les
(KiX Master)
2003-09-27 11:52 AM
Re: Enumerate remote files

Well, you still don't say what sort of logs these are so I can't say if there is an in-use issue. I did notice though that you are trying to compare a string with a value.

If ($result1 < $sub1)


Saleem
(Hey THIS is FUN)
2003-09-28 12:25 AM
Re: Enumerate remote files

Regardless of the type event log I looking for the date of the file not time.

That's why i used getfiletime() like
code:
 
$dt=GetFileTime ("\\server\eventlog\$dr")
$dt$dttrm=Left("$dt",10)
$y1 = SubStr($dttrm, Len($dttrm) - 9, 4)
$y2 = SubStr($dttrm, Len($dttrm) - 4, 2)
$y3 = SubStr($dttrm, Len($dttrm) - 1, 2)$result1=$y1 + $y2 + $y3
? $result1

This way I am getting only date of the file, I use valu to minus 7 from current date.

I know I am doing some thing crap here, Pls tell me to do better.


Les
(KiX Master)
2003-09-28 12:29 AM
Re: Enumerate remote files

Val()

LonkeroAdministrator
(KiX Master Guru)
2003-09-28 07:54 AM
Re: Enumerate remote files

yep, les is right.
change:
code:
If ($result1 < $sub1)

to:
code:
If ($sub1 > $result1)

uhm, while tried to post these lines without code-tags, board was yelling about html-tags!
wtf [Mad] [Eek!] [Mad]


Saleem
(Hey THIS is FUN)
2003-09-28 08:47 AM
Re: Enumerate remote files

Thanx Lonkero I'll change it, But that is not the main issue, How can I Enumerate remote Pc's files using DIR() function ?? If I can achive this task the rest I can do within no time.

Dir() is working fine in local but if I do it like DIR("\\server\shareddrive") it dosent work

I tried by mapping the drive too like DIR ("f:\") no use


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 08:59 AM
Re: Enumerate remote files

just issue dir() and return the error code.
I bet it's 5.

checked to see is there problem with simple scriptlet:
code:
dir("e:\") ;connected to jooel3.lonkero...fi
for $=0 to 10
dir ?
next

and it worked just fine.


Saleem
(Hey THIS is FUN)
2003-09-28 09:53 AM
Re: Enumerate remote files

Guys

I found out the issue. My script was failing not in enumeration part but in getfiletime function, This event log file name is having "@" charecter when i removed this charecter it was giving file date and time.

quote:

$ss=GetFileTime ("f:\MOSAIC01MZsec14-9-2003@8-20-5.evt")
? $ss
$ss1=GetFileTime ("f:\MOSAIC01MZsec14-9-20038-20-51.evt")
? $ss1

here $ss1 is giving the output $ss no.

there are thousends of files in the directory I cannot rename all manuelly [Roll Eyes]


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 10:01 AM
Re: Enumerate remote files

nope.
here the issue is that you write it manually.
if you want to write it, you need to read your manual:
$ss=GetFileTime ("f:\MOSAIC01MZsec14-9-2003@@8-20-5.evt")

now, did you or did you not check the error?


Saleem
(Hey THIS is FUN)
2003-09-28 10:12 AM
Re: Enumerate remote files

Lonkero

I know about "@"in kix Itried with double ("@@") too but it is not giving any result, Pls rename any of your file with "@@" and try. I am sure it will fail to produce any result.


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 10:30 AM
Re: Enumerate remote files

I did.
there are some cracks and other not so good stuff so can't show the results.
the file was readen fine.
code:
dir("e:\")
do
$=dir
$ " - " getfiletime("e:\"+$)
?
until not len($)

get $ exit 0

file tested with:
web@monitor.kix - 2003/09/25 02:50:16

I still ask you, did you or did you not check the error code???

[ 28. September 2003, 10:33: Message edited by: Lonkero ]


Saleem
(Hey THIS is FUN)
2003-09-28 11:11 AM
Re: Enumerate remote files

quote:

I still ask you, did you or did you not check the error code???

Well it is not giving any error code...

Now i am running only a one line code

code:
 
$ss=GetFileTime ("f:\MOSAIC01MZsec14-9-2003@8-20-5.evt")
? $ss

$ss is returning blank line [Mad]

as soon as I remove "@" from file name it is returning file date and time.
[Confused]


Saleem
(Hey THIS is FUN)
2003-09-28 11:13 AM
Re: Enumerate remote files

quote:

I still ask you, did you or did you not check the error code???

Well it is not giving any error code...

Now i am running only a one line code

code:
 
$ss=GetFileTime ("f:\MOSAIC01MZsec14-9-2003@8-20-5.evt")
? $ss

$ss is returning blank line [Mad]

as soon as I remove "@" from file name it is returning file date and time.
[Confused]


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 11:28 AM
Re: Enumerate remote files

lol.
make your file that SINGLE @.
and then use this:
"with normal	:" GetFileTime ("f:\MOSAIC01MZsec14-9-2003@@8-20-5.evt") ?
"error is :" @serror ? ?
"with forced :" GetFileTime ("f:\MOSAIC01MZsec14-9-2003"+chr(64)+"8-20-5.evt") ?
"error is :" @serror ? ?
"different ?"

get $


like you said, you SHOULD know, you CANT!!! use the single @-sign in the string.
how hard is that.


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 11:29 AM
Re: Enumerate remote files

saleem, btw.
not getting mad at you.
just at me, as can't explain well enough.


Saleem
(Hey THIS is FUN)
2003-09-28 11:54 AM
Re: Enumerate remote files

Sorry Lonkero

I knoe I am giving you hard time

Finelly it gave me some result.
code:
 
$ss=GetFileTime ("f:\MOSAIC01MZ@ab.evt")
? $ss
? @ERROR
$ss1=GetFileTime ("f:\MOSAIC01MZ"+Chr(64)+"ab.evt") ?
? $ss1?
@serror ?

and the reuslts are

quote:

D:\kix>kix32 filedate

123

2003/09/28 11:49:14
The operation completed successfully.

what do you think I need to rename the file name with Chr(64) ?
it's weired right ?


LonkeroAdministrator
(KiX Master Guru)
2003-09-29 12:00 AM
Re: Enumerate remote files

no.
you still didn't double the @.
chr(64) gives same results as with double @@.

I gave you that line to test do you do what I ask you to.
no, you don't.
there is no problem whatsoever if you would do as you are informed to do.


LonkeroAdministrator
(KiX Master Guru)
2003-09-29 12:02 AM
Re: Enumerate remote files

if you try with this line, it will work too:
$ss=GetFileTime ("f:\MOSAIC01MZ"+"@"+"ab.evt")

which again is same as:
$ss=GetFileTime ("f:\MOSAIC01MZ@@ab.evt")


Saleem
(Hey THIS is FUN)
2003-09-29 12:36 AM
Re: Enumerate remote files

Thnax Lonkero......

It worked..... I was doing a mistake that I was changing the file name too with two @@ (dump ass [Mad] ) now it worked.

now if we go back back to old cord

code:
 
$dt1=@date
$x1 = SubStr($dt1, Len($dt1) - 9, 4)
$x2 = SubStr($dt1, Len($dt1) - 4, 2)
$x3 = SubStr($dt1, Len($dt1) - 1, 2)
$result=$x1 + $x2 + $x3
$sub=Val($result)
$sub1=$sub-7
$dr=Dir("f:\")
While $dr <> "" AND @error = 0
$dt=GetFileTime ("f:\$dr")
? $dr
? $dt
$dttrm=Left("$dt",10)
$y1 = SubStr($dttrm, Len($dttrm) - 9, 4)
$y2 = SubStr($dttrm, Len($dttrm) - 4, 2)
$y3 = SubStr($dttrm, Len($dttrm) - 1, 2)
$result1=$y1 + $y2 + $y3
If ($sub1 > $result1)
;Del "\\mosaic01mz\eventlog\$dr"
;? "less than 7 exist"
EndIf
$DR=Dir()
Loop

I think I have to add that extra "@" to
code:
 $dt=GetFileTime ("f:\$dr") 

here somewhere right ?


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 05:30 PM
Re: Enumerate remote files

nope.
the double stuff for @ and $ and % only is effective when you do type it yourself in the scriptfile.
thus, if you read the filename, it will be in the variable and the double thing does not infect it.
but use these lines, as they "follow" best practise:
code:
$dt=GetFileTime ("f:\"+$dr)
? $dr
? $dt
$dttrm=Left($dt,10)



Les
(KiX Master)
2003-09-28 05:59 PM
Re: Enumerate remote files

Saleem,
Like I said in my first post!
quote:
You don't provide enough information.
In your code, you do:
$dt=GetFileTime ("\\server\eventlog\$dr")
? $dt

If you would have said that $dt returns nothing in your first instead of tenth post, we could have solved this with less than 22 posts!

If you cannot learn to provide more details, I will not look at any more of your posts.


Sealeopard
(KiX Master)
2003-09-29 03:14 AM
Re: Enumerate remote files

A current eventlog can never be older than seven days as it is constantly in use. However, backed-up eventlog can be older than seven days. Now, if you want to delete those eventlogs, then why do you back them up in the first place?

Alos, you cna specify how eventlogs overwriten the evententries, and you can also resize the eventlogsizes to have all events for a specific time period into them.

Thus, as other already repeatedly told you, please explain to us in detail what exactly you try to accomplish.


Saleem
(Hey THIS is FUN)
2003-09-29 05:48 AM
Re: Enumerate remote files

LLigetfa
It was not puposefully even I came to know the problem is in GetFiletime() only only when I reach 10th post. As i mentioned in my subject line I thought the problem is with Enumerating remote files.

Any way thanx for your support.

sealeopard

We have some unimportent servers which we are not spending money for backup , hence we decided to keep log files for last seven days by deleting them on weekly basis.
Geographically this servers are located in diffrent regions so I thought of writing a script to connect this servers and deleting event files centrelly.

Lonkero

I'll test the code and post the result.


Sealeopard
(KiX Master)
2003-09-29 04:24 PM
Re: Enumerate remote files

So, you're saying that the eventlogs on those "unimportant" servers are getting so big within a seven-day period, that thet needs to manually be deleted? [Eek!]

Just set "Overwrite events older than 7 days" and set the eventlog file size to e.g. 8192kB and they will purge themselves automatically.


Saleem
(Hey THIS is FUN)
2003-09-30 06:01 AM
Re: Enumerate remote files

This are our test servers, now a days we are doing some extensive application tests on this servers so some how event logs are getting heavy ver fast.

Thanx for the suggestion, good news that script is also working now.