Moving/Copying old logs

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
foglema
Posts: 3
Joined: Thu Mar 30, 2006 3:06 pm
Location: Maryland

Moving/Copying old logs

Post by foglema »

From within options/log settings I set my common log to copy at a specified time using the following script:

cmd /c move /y "%log%" "E:\HostMonitor_Old_Logs\%mm-dd-yy%.dbf"

Instead of a file named (example date) 3-30-06.dbf I get a file named %mm-dd-yy%.dbf.

I expect there is an error in my script that is preventing the system from using the month-day-year as my file name, but I do not know. Can somoene assist?
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Quote from the manual
You may specify 2 commands for execution: one for common log files, another for private logs. You may use special variables in the command line: %log% - represents full name (including path) of the log file (e.g. C:\Program Files\HostMonitor\Logs\04-2004.htm)
%logpath% - represents path to the log file (including trailing back slash. E.g. C:\Program Files\HostMonitor\Logs\)
%logname% - represents name of the log file (e.g. 04-2002.htm)
%logext% - represents extension of the log file (e.g. ".htm")
It doesn't say you can use date macro variables here.
However you may use these variables to specify the log file, so HostMonitor will create log files using name that you want. In such case you will not need to rename the file later.

Regards
Alex
foglema
Posts: 3
Joined: Thu Mar 30, 2006 3:06 pm
Location: Maryland

DBT

Post by foglema »

Thank you for the information. A follow-on question concerning the copying of logs. I use the DBF log format and have the system set to copy the Common log each day (testing for now).

In order to be able to review the copied log you also need the DBT file that is associated with that log. How can the system be set to copy the associated DBT file at the same time it copies the DBF?
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Are you sure you need DBT file? All viewers I have on my system works without this file. Log Analyzer doesn't need the file either.

If you really need the file, create BAT file and use %~n1 parameter to retrieve log file name without extension.
E.g.
BAT file: "move %~d1%~p1%~n1.* c:\hostmon\oldlog\"
Command to start: "cmd /c batfilename.bat %logfile%"

Regards
Alex
foglema
Posts: 3
Joined: Thu Mar 30, 2006 3:06 pm
Location: Maryland

Post by foglema »

Thank you, I will give this a try.

Sadly Access 2003 use the file and without out it wont open the DBF.
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Alex,


Still not possible to use macro variables other then the one´s related with test name in this option?

If so, how can I move log files and change it´s name to append the date it was moved.


Thanks a lot for helping,

Regards.

Jromariz.
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Just one more question: Where can I find info about the %~n1, %~p1 and %~d1 parameters for using in bat files?


Regards,

Jromariz.
Yoorix
Posts: 177
Joined: Wed Dec 14, 2005 8:28 am

Post by Yoorix »

jromariz wrote: how can I move log files and change it´s name to append the date it was moved.
You may try following approach. As Alex has described above, you need BAT file. Bat file contains two lines
call get_date.bat
move %~d1%~p1%~n1.* c:\hostmon\oldlog\%~n1_%Year%_%Month%_%Day%.*
Command to start is still the same: "cmd /c batfilename.bat %logfile%"

Variables %Year%,%Month%,%Day% you retrieves as result of get_date.bat execution. Below is the listing of get_date.bat
@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
Regards,
Yoorix
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Yoorix,


Thansk a lota for your help and for a complete explanation.


Best Regards,


Jromariz.
jromariz
Posts: 264
Joined: Wed Apr 03, 2002 6:00 pm
Location: Brasil

Post by jromariz »

Yoorix,


I´m facing a problem with the command move "filename.*" "newfilename.*"

It´s returning an erros. I have tested by manually trying to move a file and it really returns an error: "the file name syntax, folder name or volume is incorrect".


Any ideas?


Regards,

Jromariz.
Yoorix
Posts: 177
Joined: Wed Dec 14, 2005 8:28 am

Post by Yoorix »

jromariz wrote:I´m facing a problem with the command move "filename.*" "newfilename.*"

It´s returning an erros. I have tested by manually trying to move a file and it really returns an error: "the file name syntax, folder name or volume is incorrect".
Strange. Try execute manually following .bat file:
call get_date.bat
Echo %Year% %Month% %Day% > test.txt
Then you should take a look on test.txt. If you will able to see today date than get_date.bat works correctly.

BTW. Try to type "Date /T" in command line. What result do you see?

Also problem may appear if there are spaces in log path or file name.
Then you shoud protect logpath with ", e.g.
move "%~d1%~p1%~n1.*" "c:\hostmon\oldlog\%~n1_%Year%_%Month%_%Day%.*"

And, of course, folder c:\hostmon\oldlog\ should be created. But you may change it on your old log folder.

Regards,
Yoorix
Yoorix
Posts: 177
Joined: Wed Dec 14, 2005 8:28 am

Post by Yoorix »

According to Microsoft:
%~dI Expands %I to a drive letter only
%~pI Expands %I to a path only.
%~nI Expands %I to a file name only.

In our case "I" means "1" - first command line parameter passed into bat file.
To figure the probelm out you shoud run bat file with log file name as parameter, wrapped in ". In .bat file you may use Echo command to print something to console, e.g.:
call get_date.bat
Echo %Year% %Month% %Day%
Echo %~d1%~p1%~n1.
Echo %~n1_%Year%_%Month%_%Day%
Echo move %~d1%~p1%~n1.* c:\hostmon\oldlog\%~n1_%Year%_%Month%_%Day%.*

Regards,
Yoorix
Post Reply