View previous topic :: View next topic |
Author |
Message |
mp1
Joined: 07 Mar 2006 Posts: 200
|
Posted: Mon Feb 18, 2008 9:24 am Post subject: Problem with compage files and date macro |
|
|
Hi,
I want to check a logfile, if there is an line with the date from today.
So I tried it with the compare files test method:
file: C:\test.log (the file name is always the same)
string: %dd%.%mm%.%yyyy%
The log file looks like this:
17.02.2008 xxxxxxxxxx
18.02.2008 xxxxxxxxxxxx
18.02.2008 xxxxxx
Unfortunately I didn't get it work. I have HM 7.10.
I tried it with the translate macro option and without.
What do I wrong?
Thanks in advance
Martin |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Mon Feb 18, 2008 9:38 am Post subject: |
|
|
Sorry, "Compare files" test method does not support macro variables in the search string. "Translate macros" option is only applied to the filenames. Quote from the manual:
http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#filecmp
==========================================
If you need to check some files that are dynamically created and do not have static name (e.g. some logs that are created on daily basis and have different file name every day), you may enable "Translate macros" options. With this option enabled you may use special date macro variables and User Defined Variables in file name.
==========================================
You may try "Text Log" test method, which offers "Macros" option, that allows you to use date&time macro variables in the "look for" string/expression.
http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#textlog
Regards,
Max |
|
Back to top |
|
|
mp1
Joined: 07 Mar 2006 Posts: 200
|
Posted: Mon Feb 18, 2008 9:47 am Post subject: |
|
|
Hi Max,
Thanks for the quick reply.
I already tried it with the text log method, with no success.
Look for sting: %dd%.%mm%.%yyyy%
activated the Macros option
So the text log method only checks new entries.
I added some entries like:
18.02.2008 xxxxxxxxxxxx
18.02.2008 xxxxxx
... but got no alarm.
I also tried it with a global macro variable in the search string:
%udv_date%
udv_date = %dd%.%mm%.%yyyy%
How does the text log method check for new entries?
(file change date ... ???)
Regards,
Martin |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Mon Feb 18, 2008 10:08 am Post subject: |
|
|
Sorry, it is my fault. "Text Log" test method will not help you also. "Macros" option allows you to use global (user defined) macro variables, not date&time.
I think, you may try to use the following script within "Shell Script" test method. http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#chkShell
You just should add this script into the "Script Manager".
Start cmd: cmd /c %Script% %Params%
Script:
Code: | @echo off
REM Script retrieves system date and parse it.
REM Output variables:
REM %Year%, %Month%, %Day%
REM %iDate%,%sDate% - Date Separators from registry
rem Select date
:: Export registry's date format settings to a temporary file
START /W REGEDIT /E _TEMP.REG "HKEY_CURRENT_USER\Control Panel\International"
:: Read the exported data
FOR /F "tokens=2* delims==" %%A IN ('TYPE _TEMP.REG ^| FIND /I "iDate"') DO SET iDate=%%A
FOR /F "tokens=2* delims==" %%A IN ('TYPE _TEMP.REG ^| FIND /I "sDate"') DO SET sDate=%%A
DEL _TEMP.REG
SET iDate=%iDate:"=%
SET sDate=%sDate:"=%
IF %iDate%==0 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET Year=%%C
SET Month=%%A
SET Day=%%B
)
IF %iDate%==1 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET Year=%%C
SET Month=%%B
SET Day=%%A
)
IF %iDate%==2 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET Year=%%A
SET Month=%%B
SET Day=%%C
)
:: Remove the day of week if applicable
FOR %%A IN (%Year%) DO SET Year=%%A
FOR %%A IN (%Month%) DO SET Month=%%A
FOR %%A IN (%Day%) DO SET Day=%%A
type %1 | find "%Day%.%Month%.%Year%" > NUL
IF ERRORLEVEL 1 (
echo ScriptRes:Bad:
) ELSE (
echo ScriptRes:Ok:
) |
Script requires just one parameter - filename to check.
Regards,
Max |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12811 Location: USA
|
Posted: Mon Feb 18, 2008 10:12 am Post subject: |
|
|
Quote from the manual Quote: | Macros
With this option enabled you may use global (user defined) macro variables in the "look for" string/expression |
In your case it resolves %udv_date% to %dd%.%mm%.%yyyy% but does not processes date macro variables.
I think we can implement this option in next version of HostMonitor.
Quote: | How does the text log method check for new entries?
(file change date ... ???) |
HostMonitor checks time stamp, size of the file, also it keeps position of the last check.
Regards
Alex |
|
Back to top |
|
|
mp1
Joined: 07 Mar 2006 Posts: 200
|
Posted: Tue Feb 19, 2008 12:49 am Post subject: |
|
|
Thanks thanks,
The script works perfect.
Quote: | In your case it resolves %udv_date% to %dd%.%mm%.%yyyy% but does not processes date macro variables.
I think we can implement this option in next version of HostMonitor. |
This would be great
Best regards,
Martin |
|
Back to top |
|
|
|