Save Unique Log Files With a Windows Batch File

This may help you if you have to run a batch file and save off file with a unique name every time. I find the easiest thing is to save based on the exact time. For this file, I wanted to gather all of the processes in task manager and save them into a spreadsheet. I did this at the beginning of a load test, and the ending of a load test. I then compared the two files to determine memory utilization of each process. In XP there is a command line executable build in called “tasklist.exe” and it allows you to save your data in csv format. In this case I only chose to look at the dllhost.exe processes. The main thing I wanted to save in here was the code for setting up the timestr variable, which is the current date and time.

If you run this against another machine (not localhost) you will need to make sure you have appropriate permissions. You might want to do a “NET USE” with your credentials before running this against the remote machine to ensure you have an open connection.

-----Begin Code------
echo off
REM SET UP UNIQUE LOG FILE NAMING CONVENTION
for /f "tokens=1,2" %%u in ('date /t') do set d=%%v
for /f "tokens=1" %%u in ('time /t') do set t=%%u
if "%t:~1,1%"==":" set t=0%t%
set timestr=%d:~6,4%%d:~3,2%%d:~0,2%%t:~0,2%%t:~3,2%
 
REM RUN TASKLIST.EXE WITH OPTIONS TO SAVE AS A CSV FILE
tasklist /FI "IMAGENAME eq dllhost.exe" /S SERVER1 /U DOMAIN\USERNAME /FO CSV > tasklistlog%timestr%.csv
-----End Code----

01/08/2010 UPDATE:

My brother from another mother, Richard Bishop has expanded upon this. Check it out:

http://www.bish.co.uk/index.php?option=com_content&view=article&id=82:tasklist-log-files&catid=34:recent&Itemid=1

Enjoy! Got a cool batch file program? Send it to me at scott-at-loadtester.com

Scott

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Scott Moore

About Scott Moore (153 articles)

With over 20 years of IT experience with various platforms and technologies, Scott has tested some of the largest applications and infrastructures in the world. He is a Certified Instructor and Certified Product Consultant in HP’s LoadRunner and Performance Center products. He currently holds HP certifications for ASE, ASC, and CI. A thought leader in the APM space, he speaks regularly at IT conferences and events