Moving/Copying old logs
Moving/Copying old logs
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?
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?
Quote from the manual
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
It doesn't say you can use date macro variables here.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")
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
DBT
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?
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?
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
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
You may try following approach. As Alex has described above, you need BAT file. Bat file contains two linesjromariz wrote: how can I move log files and change it´s name to append the date it was moved.
Command to start is still the same: "cmd /c batfilename.bat %logfile%"call get_date.bat
move %~d1%~p1%~n1.* c:\hostmon\oldlog\%~n1_%Year%_%Month%_%Day%.*
Variables %Year%,%Month%,%Day% you retrieves as result of get_date.bat execution. Below is the listing of get_date.bat
Regards,@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
Yoorix
Strange. Try execute manually following .bat file: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".
Then you should take a look on test.txt. If you will able to see today date than get_date.bat works correctly.call get_date.bat
Echo %Year% %Month% %Day% > test.txt
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
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.:
Regards,
Yoorix
%~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