View previous topic :: View next topic |
Author |
Message |
dba
Joined: 08 Dec 2006 Posts: 2
|
Posted: Fri Dec 08, 2006 3:21 am Post subject: Extract string from log file |
|
|
Hello,
I'm trying to find a way to extract a value from a log file (F-Secure's HEADER.INI) and to send it back to me as a %Reply%
In that INI file, we find several values and these...
[FSAV_Database_Version]
Version=2006-12-08_03
Actually, I'd like to get 2006-12-08_03 as the Reply
I've tried with the Compare Files test (but I guess there's no way to extract value) and the Text Log test looking for string Version= with Display Found Line...
no luck :-\
Any help would be much appreciated
Thank You
David Basquin
Alternalease |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
|
Back to top |
|
|
Yoorix
Joined: 14 Dec 2005 Posts: 177
|
Posted: Fri Dec 08, 2006 6:09 am Post subject: |
|
|
Hi David.
I think, you may use Shell Script method with following script:
http://www.ks-soft.net/hostmon.eng/tests.htm#chkShell
Start cmd: cmd /c %Script% %Params%
Script :
Code: | @echo off
rem %1 - Filename full path
rem %2 - Section Name
rem %3 - Pattern string
set last_section_name=""
set string_to_parse=""
set section_start=""
set reply_value=""
set error_str="No match"
rem Step 1: Retrieving raw section line number
for /f "eol=; tokens=*" %%i in ('type %1 ^| find /N "[%2]"') do SET last_section_name=%%i
IF %last_section_name%=="" (
SET error_str="Could not locate section %2"
goto result
)
rem Step 2: Retrieving real section line number
for /f "eol=; tokens=1* delims=[" %%i in ('echo %last_section_name%') do (
for /f "eol=; tokens=1* delims=]" %%j in ('echo %%i') do SET section_start=%%j
)
rem Step 3: Retrieving line that mathes pattern
for /f "eol=; tokens=* skip=%section_start%" %%i in ('type %1') do (
echo %%i | find "%3" > NUL
IF ERRORLEVEL 1 (
rem
) ELSE (
SET string_to_parse=%%i
goto end
)
)
:end
rem echo %string_to_parse%
rem Step 4: Extracting a value from the string
for /f "eol=; tokens=* delims=" %%i in ('echo %string_to_parse%') do (
for /f "eol=; tokens=2*" %%j in ('echo %%i') do SET reply_value=%%j
)
:result
IF NOT %reply_value%=="" (
echo ScriptRes:Ok:%reply_value%
) ELSE (
echo ScriptRes:Bad:%error_str%
)
|
Script requires three params:
1. Full file name of log file
2. Section name
3. Pattern string (Version= in your case)
So, into the Params box of Test Properties Window you just should specify appropriate params, like:
C:\temp\HEADER.INI FSAV_Database_Version Version=
Please note: Script may not work with folders with space in their name, like C:\Program Files\Test, etc. In such case just copy log file into the another folder without space in name.
Regards,
Yoorix |
|
Back to top |
|
|
dba
Joined: 08 Dec 2006 Posts: 2
|
Posted: Fri Dec 08, 2006 1:22 pm Post subject: |
|
|
Thank you for your replies; your script looks awesome Yoorix ^^
I'll try both solutions on Monday.
David |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Fri Dec 08, 2006 1:36 pm Post subject: |
|
|
I am confused.
You want to check log (some file that accumulates information from some application, application adds new data to the file but does not remove/replace old data)?
Or you want to check INI file - file where the same line (e.g. line #5) may store some changeable data?
Regards
Alex |
|
Back to top |
|
|
|