Save Unique Log Files With a Windows Batch File
Posted on Jan, 2010 by Admin
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----
My brother from another mother, Richard Bishop has expanded upon this. Check it out:
Enjoy! Got a cool batch file program? Send it to me at scott-at-loadtester.com