Writing a batch script

MantridMantrid Lockpick Join Date: 2003-12-07 Member: 24109Members
So I want to make it so server logs are uploaded to the server every day. To do this, I want to write a batch script (which well be scheduled to run every day through Windows). I want to take it, rename it, and move it to a directory inside htdocs.

Now, I want to change the name of the files like this: access.log to access.log.[Date].txt

I know how to rename and move files, but how can I tell it to change the name to the date and time when the batch script is run? Is there a way to get the date, make it into a variable, and rename the file to include the variable?

Comments

  • RoverRover blargh Join Date: 2003-09-23 Member: 21139Members
    <a href="http://www.tech-recipes.com/computer_programming_tips956.html" target="_blank">this?</a> 3 second google.
  • WyzcrakWyzcrak Pot Pie Aficionado Join Date: 2002-12-04 Member: 10447Forum Moderators, Constellation, NS2 Playtester, Squad Five Blue
    Sure, but he needs date and time.

    Here's an adaptation of something I <a href="http://groups.google.com/group/microsoft.public.win2000.general/browse_frm/thread/6923e0e636f60ec2/85d9c811cca3dbe5%2385d9c811cca3dbe5" target="_blank">found</a>:
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
    for /F "tokens=1-2 delims=:." %%a in ('echo %time%') do set hour=%%a& set min=%%b
    if %hour% LSS 10 (set time_=0%hour%%min%) else (set time_=%hour%%min%)
    for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do set datetime=%%c%%a%%b%time_%
    echo Datetime is %datetime%
    <!--c2--></div><!--ec2-->
  • BlackMageBlackMage [citation needed] Join Date: 2003-06-18 Member: 17474Members, Constellation
    edited February 2007
    here's a <a href="http://www.salesianer.de/util/apachelog.html" target="_blank">Perl script</a> (that can be converted for use with windows)

    this is a win32 tuturial-y thing (batch files and such): <a href="http://www.sprint.net.au/~terbut/usefulbox/apachelogrot.htm" target="_blank">http://www.sprint.net.au/~terbut/usefulbox/apachelogrot.htm</a>
Sign In or Register to comment.