A better way for logging?

  • Thread starter Thread starter Jim in Arizona
  • Start date Start date
J

Jim in Arizona

I made a simple batch that just copies the back end of an access database
from one computer, then from that computer to another, as shown below.

xcopy "\\comp1\database\HRZNDATA.mdb" "\\comp2\database\" /E /C /F /R /Y >
"\\comp\database\comp1_to_comp2.log"
xcopy "\\comp2\database\HRZNDATA.mdb" "\\comp3\database\" /E /C /F /R /Y >
"\\comp\database\comp2_to_comp3.log"

This will leave two text files that just tells me that one file has been
copied (in each file) and time stamp the document. This is ok, but is there
a better way, such as having the batch write time stamps within the text
file and continue to write to the log file, line by line, night by night, so
it isn't replaced every night with a new copy with just a single entry?

TIA,
Jim
 
Jim said:
I made a simple batch that just copies the back end of an access database
from one computer, then from that computer to another, as shown below.

xcopy "\\comp1\database\HRZNDATA.mdb" "\\comp2\database\" /E /C /F /R /Y >
"\\comp\database\comp1_to_comp2.log"
xcopy "\\comp2\database\HRZNDATA.mdb" "\\comp3\database\" /E /C /F /R /Y >
"\\comp\database\comp2_to_comp3.log"

This will leave two text files that just tells me that one file has been
copied (in each file) and time stamp the document. This is ok, but is there
a better way, such as having the batch write time stamps within the text
file and continue to write to the log file, line by line, night by night, so
it isn't replaced every night with a new copy with just a single entry?

TIA,
Jim

Use '>>' instead of '>'.

Use

echo/%date% %time% >> "\\comp\database\comp2_to_comp3.log"

to append the date and time to your log file. If you wanted to get
fancy, you could use

echo/%date:~10,4%/%date:~4,5% %date:~0,3% %time% >> ...

instead.
 
This is a little diddy i use in my back up scripts for time stamps, it
is very configurable on how you wanna represent time.
Note: if you are testing this in a CMD window change %% to % if this is
in a batch script it runs perfectly.

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=(%%i)
%%l.%%j.%%k
for /f "Tokens=1" %%i in ('time /t') do set tm=.%%i
set tm=%tm::=.%
set dtt=%dt%%tm%
echo %dtt% >> file.txt

Also since you are coping the files across the network you might wanna
add /Z (Copies networked files in restartable mode) to it as well...
just to be safe
 
This is a little diddy i use in my back up scripts for time stamps, it
is very configurable on how you wanna represent time.
Note: if you are testing this in a CMD window change %% to % if this is
in a batch script it runs perfectly.

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=(%%i)
%%l.%%j.%%k
for /f "Tokens=1" %%i in ('time /t') do set tm=.%%i
set tm=%tm::=.%
set dtt=%dt%%tm%
echo %dtt% >> file.txt

This 'time' value is not very useful because you are not accounting for
'AM' or 'PM'. To just have the time displayed as '03.22' doesn't tell
me if it was morning or afternoon. If you wanted to drop the 'PM',
then you should add 12 to the hour value to get a meaningful log entry.
 
This 'time' value is not very useful because you are not accounting for
'AM' or 'PM'. To just have the time displayed as '03.22' doesn't tell
me if it was morning or afternoon. If you wanted to drop the 'PM',
then you should add 12 to the hour value to get a meaningful log entry.

His system is probably set for 24-hour time, as mine is. When I tried the
batch file, I got (Wed) 2005.12.14.18.58.
 
Gary said:
His system is probably set for 24-hour time, as mine is. When I tried the
batch file, I got (Wed) 2005.12.14.18.58.

That's a good point. I haven't used 'time /t' since the good ol' NT4.0
days. :-) But with '%time%' it's not an issue whether the system is set
for 24-hour time or not.
 
Also since you are coping the files across the network you might wanna
add /Z (Copies networked files in restartable mode) to it as well...
just to be safe

Phil Robyn wrote:

I've seen that option dozens of times but I don't know what it means by
'restartable' mode. Can you or someone fill me in?

Thanks!
 
Use '>>' instead of '>'.
Use

echo/%date% %time% >> "\\comp\database\comp2_to_comp3.log"

to append the date and time to your log file. If you wanted to get
fancy, you could use

echo/%date:~10,4%/%date:~4,5% %date:~0,3% %time% >> ...

instead.

Thanks Phil.

In the end, my script looked like this and works well (watch for word wrap)
assuming the MDB isn't locked.

echo/%date% %time% >> "\\comp2\server\hrzndata.log"
xcopy "\\comp1\server\HRZNDATA.mdb" "\\comp2\server\" /E /C /F /R /Y >>
"\\comp2\server\hrzndata.log"
echo ---------------------------------------------- >>
"\\comp2\server\hrzndata.log"
echo/%date% %time% >> "\\comp2\server\hrzndata.log"
xcopy "\\comp2\server\HRZNDATA.mdb" "\\comp3\database\" /E /C /F /R /Y >>
"\\comp2\server\hrzndata.log"
echo ============================================== >>
"\\comp2\server\hrzndata.log"

This seperates files copied and days ran with lines, which makes it a little
easier to read.

Thanks for the help!

Jim
 
Back
Top