#189295 - 2008-08-27 01:49 PM
Read Content from .log- file
|
Schwinni
Fresh Scripter
Registered: 2008-06-09
Posts: 8
|
Hello everybody,
is there a possibility to let kix check the content of a file?
I would like to use kix to open a created *.log- file (textfile) and check the content if the phrase "Skipped with error" is included. It is always this sentence, if errors occur! If yes, kix should send a mail with "error" in subject line, else send mail with "success" in Subject line.
Thanks for your help Michael
|
|
Top
|
|
|
|
#189296 - 2008-08-27 02:17 PM
Re: Read Content from .log- file
[Re: Schwinni]
|
BradV
Seasoned Scripter
  
Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
|
Sure,
Check out the manual for Open and InStr. Rough example might be:
If Open(1,"my.log") = 0
$strLine = ReadLine(1)
While @ERROR = 0
If Instr($strLine,"Skipped with error") <> 0
? "Found it!"
EndIf
$strLine = ReadLine(1)
Loop
EndIf
Regards,
Brad V
|
|
Top
|
|
|
|
#189299 - 2008-08-27 05:10 PM
Re: Read Content from .log- file
[Re: Glenn Barnas]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
To contract on Glenn's thoughts 
$strLine = ReadLine(1)
While Not $Tag And Not @ERROR
$Tag=InStr($strLine, 'Skipped with error')
$strLine = ReadLine(1)
Loop
$=Close(1)
If $Tag ; string was found!
; use Blat to send a "skipped found" email
Else
; use Blat to send an "skipped not found" email
EndIf
Gotta save those CPU cycles.
|
|
Top
|
|
|
|
#189876 - 2008-09-25 01:44 PM
Re: Read Content from .log- file
[Re: BradV]
|
Kaiminator
Fresh Scripter
Registered: 2006-08-28
Posts: 17
|
If Open(1,"my.log") = 0
$strLine = ReadLine(1)
While @ERROR = 0
If Instr($strLine,"Skipped with error") <> 0
? "Found it!"
EndIf
$strLine = ReadLine(1)
Loop
EndIf
this example works for me. But how is the best way to parse only the last found line in the log file? i dont need all lines, which the phrase is found, i only need the last line
thanx in advance
Edited by Kaiminator (2008-09-25 01:45 PM)
|
|
Top
|
|
|
|
#189880 - 2008-09-25 03:15 PM
Re: Read Content from .log- file
[Re: Allen]
|
Kaiminator
Fresh Scripter
Registered: 2006-08-28
Posts: 17
|
thx. found this solution by myself. i keep the last value in the var
|
|
Top
|
|
|
|
#189954 - 2008-10-01 11:28 AM
Re: Read Content from .log- file
[Re: Kaiminator]
|
Kaiminator
Fresh Scripter
Registered: 2006-08-28
Posts: 17
|
sorry, one more question. Dont know, if its better to open a new topic or not.
i write several values of variables to a textfile. this looks like this:
username;path to myfiles;size;networkpath;size;date last backup
this script starts with every user logon in user context. So far - so good.
How can i manage this, that the script looks in the textfile for the username and overwrites this line with the new values?
|
|
Top
|
|
|
|
#189957 - 2008-10-01 01:32 PM
Re: Read Content from .log- file
[Re: Mart]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
This is an ideal application for an INI file, where you look for data based on a key. You can reduce the read/write to two lines of code:
$Array = Split(ReadProfileString('MyData.ini', 'USERDATA', USERID), ';') to read your ";" delimited string into an array, and
$ = WriteProfileString('MyData.ini', 'USERDATA', @USERID, Join($Array, ';')) to write the array back to a delimited string. The resulting file will look like this for user JSmith:
[USERDATA]
JSmith=username;path to myfiles;size;networkpath;size;date last backup
Of course, you can extend this concept and write individual values by using the UserID as the section. To Write:
$ = WriteProfileString('MyData.ini', @USERID, 'User', $UserName)
$ = WriteProfileString('MyData.ini', @USERID, 'Path', $Path2MyFiles)
$ = WriteProfileString('MyData.ini', @USERID, 'Size1', $DSize)
$ = WriteProfileString('MyData.ini', @USERID, 'NetPath', $NetPath)
$ = WriteProfileString('MyData.ini', @USERID, 'Size2', $NSize)
$ = WriteProfileString('MyData.ini', @USERID, 'Backup', $LastBackup) which allows you to directly read the user's values with:
$UserName = ReadProfileString('MyData.ini', @USERID, 'User')
$Path2MyFiles = ReadProfileString('MyData.ini', @USERID, 'User')
$DSize = ReadProfileString('MyData.ini', @USERID, 'User')
$NetPath = ReadProfileString('MyData.ini', @USERID, 'User')
$NSize = ReadProfileString('MyData.ini', @USERID, 'User')
$LastBackup = ReadProfileString('MyData.ini', @USERID, 'User') In this manner, you don't need to deal with (or worry about mangling) the data from other users. Think of INI files as a simple database with records (sections) and fields (section values).
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|