#172597 - 2007-01-09 08:01 PM
Re: HELP! use GetFileTime function to add line to log file
[Re: beejay]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Okay beejay, since you've been attempting to learn how to do it I'll give you an A for effort and I'll provide you with some working code.
As with most scripts it can be accomplished many ways and my example is just one of many.
;Set options
If Not @LogonMode
Break On
Else
Break Off
EndIf
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')
;Declare our variables
Dim $TimeStamp, $LogFile1, $LogFile2, $Handle, $WL, $OpenFile, $CloseFile
Dim $Result1, $Result2
Dim $Result1string, $Result2string
;Use Split and Join to put the date and time into a variable
$TimeStamp = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),''))
;Place our Logfile locations into variables
$LogFile1 = 'I:\TEST\auditfile1.txt'
$logfile2 = 'I:\TEST\auditfile2.txt'
;Place the files we want to get the file time from into variables
$Result1 = GetFileTime('C:\Program Files\filename1.txt',0)
$Result2 = GetFileTime('C:\Program Files\filename2.txt',0)
;Place the full results into variables including a comma for csv style format
$Result1string = $TIMESTAMP + ',' + @WKSTA + ',' + $Result1
$Result2string = $TIMESTAMP + ',' + @WKSTA + ',' + $Result2
;Use FreeFileHandle to find an available file handle to use
$Handle = FreeFileHandle()
If $Handle > 0
$OpenFile = Open($Handle,$LogFile1,5)
If @ERROR
'Error opening LogFile1: ' + @ERROR + ' - ' + @SERROR ?
Else
$WL = WriteLine($Handle, $Result1string)
If @ERROR
'Error updating LogFile1: ' + @ERROR + ' - ' + @SERROR ?
EndIf
EndIf
$CloseFile = Close($Handle)
EndIf
;We close the file and move on to the next file
;If we did not close the file we could not use the same variable for the Handle
$Handle = FreeFileHandle()
If $Handle > 0
$OpenFile = Open($Handle,$LogFile2,5)
If @ERROR
'Error opening LogFile2: ' + @ERROR + ' - ' + @SERROR ?
Else
$WL = WriteLine($Handle, $Result1string)
If @ERROR
'Error updating LogFile2: ' + @ERROR + ' - ' + @SERROR ?
EndIf
EndIf
$CloseFile = Close($Handle)
EndIf
.
|
Top
|
|
|
|
#172615 - 2007-01-10 09:16 AM
Re: HELP! use GetFileTime function to add line to log file
[Re: beejay]
|
beejay
Fresh Scripter
Registered: 2007-01-04
Posts: 12
|
Here's my revised code - but It's still not doing the trick. - it's not beeping either ; * Create the TIMESTAMP
; a TIMESTAMP is not strictly necessary!
IF @MONTHNO < 10
$MONTH= "0" + "@MONTHNO"
ELSE
$MONTH= "@MONTHNO"
ENDIF
IF @MDAYNO < 10
$DAY= "0" + "@MDAYNO"
ELSE
$DAY= "@MDAYNO"
ENDIF
$timestamp = "@YEAR" + "-" + "$MONTH" + "-" + "$DAY" + " " + @TIME
$ComputerName = @WKSTA
$logfile1 = "I:\foldername\auditfile1.txt"
$logfile2 = "I:\foldername\auditfile2.txt"
$Result1 = GetFileTime("C:\Program Files\filename1.txt", 0)
$Result2 = GetFileTime("C:\Program Files\filename2.txt", 0)
$Result1string = "$TIMESTAMP;$ComputerName;$Result1"
$Result2string = "$TIMESTAMP;$ComputerName;$Result2"
? IF Open(3, $logfile1, 4 ) = 0
$x = WriteLine( 3 , $Result1string + Chr(13) + Chr(10) )
if @error
beep
"Failed to write to the darn file. " @error ?
else
"write succeeded." ?
endif
ELSE
BEEP
? "failed to open file, error code : [" + @ERROR + "]"
ENDIF
sleep 2
If Close(3)
Beep
? "Error closing file!"
EndIf
? IF Open(3, $logfile2, 4 ) = 0
$x = WriteLine( 3 , $Result2string + Chr(13) + Chr(10) )
if @error
beep
"Failed to write to the darn file. " @error ?
else
"write succeeded." ?
endif
ELSE
BEEP
? "failed to open file, error code : [" + @ERROR + "]"
ENDIF
sleep 2
exit
|
Top
|
|
|
|
#172620 - 2007-01-10 11:37 AM
Re: HELP! use GetFileTime function to add line to log file
[Re: NTDOC]
|
beejay
Fresh Scripter
Registered: 2007-01-04
Posts: 12
|
NTDOC:
OK - Thanks & goodnight - I'll try adapting it & let you / colleagues know if I manage to overcome this little b******
Cheers
|
Top
|
|
|
|
#172623 - 2007-01-10 02:31 PM
Re: HELP! use GetFileTime function to add line to log file
[Re: beejay]
|
beejay
Fresh Scripter
Registered: 2007-01-04
Posts: 12
|
Hi all
I've tried a few tweaks and to simplify the code - the latest effort is below, but I still can't get the little b***** to play ball & do the job.
getting very frustrated with this one
Thanks from one kixtart novice
; * Create the TIMESTAMP
; a TIMESTAMP is not strictly necessary!
IF @MONTHNO < 10
$MONTH= "0" + "@MONTHNO"
ELSE
$MONTH= "@MONTHNO"
ENDIF
IF @MDAYNO < 10
$DAY= "0" + "@MDAYNO"
ELSE
$DAY= "@MDAYNO"
ENDIF
$timestamp = "@YEAR" + "-" + "$MONTH" + "-" + "$DAY" + " " + @TIME
$ComputerName = @WKSTA
$logfile1 = "I:\foldername\auditfile1.txt"
$logfile2 = "I:\foldername\auditfile2.txt"
$Result1 = GetFileTime("C:\Program Files\filename1.txt", 0)
$Result2 = GetFileTime("C:\Program Files\filename2.txt", 0)
IF Open( 3 , "I:\foldername\auditfile1.txt" , 5 ) = 0
$x = WriteLine( 3 , $TIMESTAMP;$ComputerName;$Result1 + Chr(13) + Chr(10) )
ELSE
BEEP
? "failed to open file, error code : [" + @ERROR + "]"
ENDIF
If Close(3)
Beep
? "Error closing file!"
EndIf
IF Open( 3 , "I:\foldername\auditfile2.txt" , 5 ) = 0
$x = WriteLine( 3 , $TIMESTAMP;$ComputerName;$Result2 + Chr(13) + Chr(10) )
ELSE
BEEP
? "failed to open file, error code : [" + @ERROR + "]"
ENDIF
If Close(3)
Beep
? "Error closing file!"
EndIf
exit
|
Top
|
|
|
|
#172627 - 2007-01-10 04:13 PM
Re: HELP! use GetFileTime function to add line to log file
[Re: beejay]
|
beejay
Fresh Scripter
Registered: 2007-01-04
Posts: 12
|
NTDOC:
I've used your script that you did last night - thanks for spending time on it; on logging on, however, the screen displays an error message for a fraction of a second:
000Script error : expected expression !. $SO=SetOption('Explicit','On')
it doesn't add any data to the log files as requested.
Does this error mean anything to you? (sorry but I don't know)
As ever, entirely grateful.
|
Top
|
|
|
|
#172683 - 2007-01-11 11:44 AM
Re: HELP! use GetFileTime function to add line to log file
[Re: NTDOC]
|
beejay
Fresh Scripter
Registered: 2007-01-04
Posts: 12
|
I've updated to 4.53 version replacing ALL 6 kixtart files (before I had only replaced kix32.exe (windows 2003 server) as in the guidance - and EUREKA!!!.
Before I sign off (until next time) a big THANK YOU to all involved, for your patience and help, especially NTDOC for writing the script now in use.
Au revoir
Beejay
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 980 anonymous users online.
|
|
|