Page 1 of 2 12>
Topic Options
#76893 - 2003-09-27 10:49 AM Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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 ??
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76894 - 2003-09-27 11:27 AM Re: Enumerate remote files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#76895 - 2003-09-27 11:37 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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.
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76896 - 2003-09-27 11:52 AM Re: Enumerate remote files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#76897 - 2003-09-28 12:25 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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.
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76898 - 2003-09-28 12:29 AM Re: Enumerate remote files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Val()
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#76899 - 2003-09-28 07:54 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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]
_________________________
!

download KiXnet

Top
#76900 - 2003-09-28 08:47 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76901 - 2003-09-28 08:59 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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.
_________________________
!

download KiXnet

Top
#76902 - 2003-09-28 09:53 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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]
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76903 - 2003-09-28 10:01 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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?
_________________________
!

download KiXnet

Top
#76904 - 2003-09-28 10:12 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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.
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76905 - 2003-09-28 10:30 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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 ]
_________________________
!

download KiXnet

Top
#76906 - 2003-09-28 11:11 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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]
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76907 - 2003-09-28 11:13 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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]
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76908 - 2003-09-28 11:28 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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.
_________________________
!

download KiXnet

Top
#76909 - 2003-09-28 11:29 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
saleem, btw.
not getting mad at you.
just at me, as can't explain well enough.
_________________________
!

download KiXnet

Top
#76910 - 2003-09-28 11:54 AM Re: Enumerate remote files
Saleem Offline
Hey THIS is FUN
*

Registered: 2001-04-11
Posts: 280
Loc: UAE
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 ?
_________________________
“I’ll not change you unless you don’t have intention to change yourself” --H:Quran

Top
#76911 - 2003-09-29 12:00 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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.
_________________________
!

download KiXnet

Top
#76912 - 2003-09-29 12:02 AM Re: Enumerate remote files
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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")
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 162 anonymous users online.
Newest Members
Jodey, Hiker, GTRoberts, KatieQuinn, Brennnnn
17684 Registered Users

Generated in 0.043 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

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