Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bat file question 2

Status
Not open for further replies.

SgtB

IS-IT--Management
Oct 3, 2002
447
0
0
US
We have a script that runs, and we want to write the output of that batch file into a log file. As of right now the script runs, and writes to the log file. We'd like to have the script create a new file if previous log file exists.
Example:
Script runs, writes to log.log
Script runs again, sees that log.log already exists, so it writes to log1.log (log2.log, log3.log etc.)

What can I do to get this done?

Thanks! ________________________________________
Check out
 
I'd recommend having the script add to the end of the existing log file instead. This way, your log won't be overwritten, and you won't have a plethora of log files to keep track of.
 
HI SgtB,

You need to have seperate log files ! right ... for that thing you have define strings by using commnd "for"

e.g.

for /f "tokens=2-5 delims=/ " %%a in ('date /t') do (
set mm=%%a
set dd=%%b
set yyyy=%%c)

Set FileN=%dd%-%mm%-%yyyy%
Set FileA=%dd%-%mm%-%yyyy%
Set FileT=""

for /f "tokens=1-5 delims=: " %%a in ('time /t') do (
set hh=%%a
set mim=%%b)
Set FileT=%hh%-%mim%





Then just specify the log file name as "log-%filen%-%filet%.log" in this %filen% will indicate the date and %filet% indicates the time when script ran.

This is little bit compicated but by this you will get the differebt log files with the time when your script ran.

HTH

Aslam
 
try to add this to your batch file:
/l "c:\winnt\backup.log"
I don't know if you already know what /l is, but it determines where the log file for backup is stored.
This is what I have and it just add the logs for 10 days until I manually delete them.
 
Thanks for all the help!

I'll try to implement your suggestion Aslamvs, looks like it will work prefectly! ________________________________________
Check out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top