Writing a batch script
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?
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
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-->
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>