KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Extract string from log file

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
dba



Joined: 08 Dec 2006
Posts: 2

PostPosted: Fri Dec 08, 2006 3:21 am    Post subject: Extract string from log file Reply with quote

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
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Fri Dec 08, 2006 5:58 am    Post subject: Reply with quote

If you are sure there that entry "Version=" exists in [FSAV_Database_Version] section only, you may use "Text Log" test method with following parameters:
Look for string Version=
Warn of all new events Display:
Item to display : found
Display text from pos #9 to pos #50
http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#textlog

On the another hand, you may use Schell Script test method:
http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell
In this case you should create cmd script, that would parse log file and retrieve necessary information.

Regards,
Max
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Yoorix



Joined: 14 Dec 2005
Posts: 177

PostPosted: Fri Dec 08, 2006 6:09 am    Post subject: Reply with quote

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
View user's profile Send private message
dba



Joined: 08 Dec 2006
Posts: 2

PostPosted: Fri Dec 08, 2006 1:22 pm    Post subject: Reply with quote

Thank you for your replies; your script looks awesome Yoorix ^^
I'll try both solutions on Monday.

David
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Fri Dec 08, 2006 1:36 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index