Need help writing batch script

Microsoft Windows xp professional w/ sp2
December 24, 2009 at 03:45:49
Specs: Windows XP, 6 GB Ram
I am trying to write a batch script which would give me the following type . i need to direct the output of a utility command to a txt file . The thing is the script would run daily and the output file should be stored in a datawise text file without overwriting the previous day file , instead it should write into a new file which shud be like test_122409 and the next day it would be test_122509 . Can anyone help me on this

See More: Need help writing batch script

Report •


#1
December 24, 2009 at 04:48:18
Something like this?


Batchfile:
http://pastebin.com/m258c0505


Report •

#2
December 24, 2009 at 05:00:04
Hi kumar

this should help u.. the output of dir command is stored in the file... based on the current system date the file name changes..

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
dir >> test_%date%

Regards
X-TechKid


Report •

#3
January 7, 2010 at 12:34:41
 i need to direct the output of a utility command to a txt file . The thing is the script would run daily and the output file should be stored in a datawise text file without overwriting the previous day file , instead it should write into a new file which shud be like test_122409 and the next day it would be test_122509 . Can anyone help me on this 

If you have biterscripting on your computer, you can invoke the utility from biterscripting with this command.

system "utility command" > { echo ("test_"+gettime()) }

It will execute the utility command and redirect its output to file test_<timestamp>.


You can download biterscripting from http://www.biterscripting.com or any other local download site.



Report •

Related Solutions

#4
January 7, 2010 at 13:32:34
Attention shoppers,

There is no consistency to %DATE% layout.

=========================================

@echo off & setLocal enableDELAYedexpansion

call :YMD
:: next line is where you run your util and put the output into today's log
::myutil > test_!YMD!

goto :eof

:YMD
::== YMD14.bat

@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9                                                                  ) do if errorlevel %%a set DD=0%%a
for %%a in (                  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set DD=%%a
echo Date %DD%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9         ) do if errorlevel %%a set MM=0%%a
for %%a in (                  10 11 12) do if errorlevel %%a set MM=%%a
echo Month %MM%

year
if errorlevel 215 set YYYY=2007
if errorlevel 216 set YYYY=2008
if errorlevel 217 set YYYY=2009
if errorlevel 218 set YYYY=2010
if errorlevel 219 set YYYY=2011
if errorlevel 220 set YYYY=2012
echo Year %YYYY%

set   YMD=%YYYY%%MM%%DD%
echo YMD is: %YMD%

del day.com
del month.com
del year.com
del dat.com

::============================ DONE YMD14 ==========================

goto :eof


=====================================
Helping others achieve escape felicity

M2


Report •

#5
January 7, 2010 at 13:49:29
I think this code might be a little simpler...

@echo off

Set Day=%Date:~-7,2%
Set Month=%Date:~-10,2%
Set Year=%Date:~-4,4%
Set TodaysDate=%Year%%Month%%Day%

YourProgram.exe > Test%TodaysDate%.txt

but I could be wrong. I still like X-TechKid's code. It should work fine too.


Report •

#6
January 7, 2010 at 14:03:00
It's much simpler. Problem is, it probably won't work.

HINT: see first two lines of #4


=====================================
Helping others achieve escape felicity

M2


Report •

#7
January 7, 2010 at 14:40:36
i downsized the date program for my library of usefuls:
@goto :AAA
e 100 8A 1E 82 00 80 CB 20 B4 2A CD 21 80 FB 77 74 10
e 110 88 C8 80 FB 79 74 09 88 F0 80 FB 6D 74 02 88 D0
e 120 B4 4C CD 21 03 B4 4C CD 21
RCX
30
W
Q

:AAA
@echo off
if not %OS%!==! setLocal enableDELAYedexpansion
debug dmy.com < date1.bat > nul 2>nul
dmy d
set dd=%errorlevel%
if "%dd:~1%" equ "" set dd=0%dd%
echo Day %DD%

dmy w
set days=Sunday Monday Tuesday WednesdayThursday Friday Saturday
set /a ee=%errorlevel%*9
set day=!days:~%ee%,9!
dofw: !day!

dmy m
set mm=%errorlevel%
if "%mm:~1%" equ "" set mm=0%mm%
month: !mm!

dmy y
set /a yyyy=%errorlevel%+1792
echo Year %YYYY%

set YMD=%YYYY%%MM%%DD%
echo YMD is: %YMD%


Report •

#8
January 7, 2010 at 15:15:50
Cool,

I'll study it.


=====================================
Helping others achieve escape felicity

M2


Report •

#9
January 7, 2010 at 23:14:20
Thanks all for the reply . it worked for me .

Report •


Ask Question