PC Review


Reply
Thread Tools Rate Thread

A better way for logging?

 
 
Jim in Arizona
Guest
Posts: n/a
 
      13th Dec 2005
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


 
Reply With Quote
 
 
 
 
Phil Robyn
Guest
Posts: n/a
 
      14th Dec 2005
Jim in Arizona wrote:
> 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.

--
Phil Robyn [Microsoft MVP]
University of California, Berkeley
 
Reply With Quote
 
sidjohn1@yahoo.com
Guest
Posts: n/a
 
      14th Dec 2005
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

Phil Robyn wrote:
> Jim in Arizona wrote:
> > 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.
>
> --
> Phil Robyn [Microsoft MVP]
> University of California, Berkeley


 
Reply With Quote
 
Phil Robyn
Guest
Posts: n/a
 
      14th Dec 2005
(E-Mail Removed) wrote:
> 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.

--
Phil Robyn [Microsoft MVP]
University of California, Berkeley
 
Reply With Quote
 
Gary Smith
Guest
Posts: n/a
 
      15th Dec 2005
Phil Robyn <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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.


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 L. Smith
Columbus, Ohio
 
Reply With Quote
 
Phil Robyn
Guest
Posts: n/a
 
      15th Dec 2005
Gary Smith wrote:
> Phil Robyn <(E-Mail Removed)> wrote:
>
>>(E-Mail Removed) wrote:
>>
>>>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.

>
>
> 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.

--
Phil Robyn [Microsoft MVP]
University of California, Berkeley
 
Reply With Quote
 
Jim in Arizona
Guest
Posts: n/a
 
      16th Dec 2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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!


 
Reply With Quote
 
Jim in Arizona
Guest
Posts: n/a
 
      16th Dec 2005
> 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.
>
> --
> Phil Robyn [Microsoft MVP]
> University of California, Berkeley


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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
logging on boot like logging to microdoft network Wizard number next Windows XP Security 0 29th Jan 2008 07:52 PM
How to add components of Microsoft Office without Logging out and Logging in as Admin Herbert Chan Windows XP General 2 13th Dec 2007 05:38 AM
logging sink for logging application block chawes40@yahoo.com Microsoft C# .NET 0 27th Jan 2006 06:22 PM
Re: custom logging sink for logging application block Ollie Riches Microsoft Dot NET Framework 0 1st Sep 2005 05:40 PM
Windows 2000 Server logging out immediatly after logging in? Tim Microsoft Windows 2000 0 15th Jul 2004 09:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:20 AM.