Computing.Net > Forums > Disk Operating System > Inserting date/time in log file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Inserting date/time in log file

Reply to Message Icon

Name: Seymour
Date: January 25, 2002 at 09:08:23 Pacific
Comment:

I am trying to find a switch or command that will include the date and time in a log file generated by a batch backup job I have written. In it's current form it generates a list of the files and directories that have been backed up and appends it to the end of the log file, but I need to know when each backup was run.

This is what I have written so far....
----------------
@echo off
echo ********* Backup started ******* >> f:\test\backuplog.txt
echo * >>f:\test\backuplog.txt

xcopy32 c:\temp\favs f:\test /d /s /c /r /y >> f:\test\backuplog.txt

echo * >>f:\test\backuplog.txt
echo ******** Backup Completed ***** >> f:\test\backuplog.txt
echo off
---------------
I would like the date and time to insert immediately after the "Backup started" line.

Please help me if you can. Many thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Adam
Date: January 25, 2002 at 09:27:15 Pacific
Reply:

Well, if you want to add the date and time to a file that already exists, you will need to append the date and time to that file. So the file is f:\test\backuplog.txt. What you'd do is this:

DATE /T >>f:\test\backuplog.txt
TIME /T >>f:\test\backuplog.txt

In case you're wondering, the "/T" command makes it so that it just displays the date or time rather than asking for a new date or time. I hope that works out for you!


0

Response Number 2
Name: Seymour
Date: January 25, 2002 at 09:45:44 Pacific
Reply:

Thanks. I have just inserted this into the BAT file and run it, and it inserts the request for a new date and time into the log file. Plus you need to press enter twice on the blank command prompt to make it complete. Any further setting required?



0

Response Number 3
Name: Laurence
Date: January 25, 2002 at 13:43:26 Pacific
Reply:

Watch for wrapped lines!

Place this in your batch file.


@ECHO off
%COMSPEC%/CFOR %%v in (1 2) do prompt Backup started$q$d $t$_>>%temp%.\backup.tmp
FIND "=" >f:\test\backuplog.txt
DEL %temp%.\backup.tmp
type f:\test\backuplog.txt



0

Response Number 4
Name: Laurence
Date: January 25, 2002 at 13:45:27 Pacific
Reply:

Man I hate this mesage board,
it really sucks - I mean the
messaging mechanics stink.

BTW, the TYPE line was just for
demonstration.


0

Response Number 5
Name: Adam
Date: January 25, 2002 at 15:43:58 Pacific
Reply:

Seymour, you say that it inserts the request for a new date and time into the log file. What version of DOS are you using? The "/T" command should eliminate that.


0

Related Posts

See More



Response Number 6
Name: Seymour
Date: January 28, 2002 at 02:04:04 Pacific
Reply:

Thanks Adam and Laurence - much appreciated.

Laurence - sorry mate, your stuff was so far over my head I just had to laugh! Where does it wrap, and where are the carriage returns? I pasted your work in and tried it but the job never completes. Any ideas?

Adam - It's the DOS shell within Windows 98. When the job is run it outputs the date/time requests into the log file. Pressing enter twice on the blank command prompt screen allows the job to complete but doesn't actually insert the date/time.

Thankyou both for your help


0

Response Number 7
Name: fool
Date: January 29, 2002 at 22:32:25 Pacific
Reply:

i wish to offer an alternative to long commands;
if you goto 'my programs' you will find 'time-date logger' this will append to c:\logfile.txt, the current time/date.

it is just a 5-minute job.
enjoy


0

Response Number 8
Name: Seymour
Date: January 31, 2002 at 03:17:45 Pacific
Reply:

Fool, nice app, but I need to be able to specify the log file's name and location. Is there an expanded configuration option?


0

Response Number 9
Name: Lee
Date: February 26, 2002 at 14:42:48 Pacific
Reply:

Windows 2000 has hidden %date% and %time% variables. You can "echo %date% %time%" and it will spit the current date/time.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Norton Ghost disk (Dos) w... The Doofus



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Inserting date/time in log file

include date/time in copy filename www.computing.net/answers/dos/include-datetime-in-copy-filename/16493.html

Delete files listed in *.log file www.computing.net/answers/dos/delete-files-listed-in-log-file/12160.html

Creating a log file to keep files name www.computing.net/answers/dos/creating-a-log-file-to-keep-files-name/17043.html