Link to home
Start Free TrialLog in
Avatar of RickJames
RickJames

asked on

Sysinternals ProcDump Script

Hello Experts,

I am having difficulty scripting ProcDump to actively monitor/attach to a process and when the process terminates, crashes, or hangs to take a Full Dump and finally continue to listen in a loop for the next instance of the processes' start for ProcDump to attach/monitor etc...

I would like for the dumps of the process (a service) to be limited to 4 dumps and overwrite the oldest dump file at each dump exceeding the 4th dump.

Below are the command line switches I am using
cd D:\ProcDump\
START ""/min "procdump" -e -h -t -ma "SomeProcess.exe" -accepteula SomeProcessDump.dmp"

http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx

Thank you,
Avatar of RickJames
RickJames

ASKER

Below is close, however between each loop I need to terminate ProcDump without killing the process, in the Procdump command window message "Press Ctrl-C to end monitoring without terminating the process" seems to be my only option.  How do I 'pipe' in Ctrl-C so at each loop so I can then start a new 'ProcDump/someprocess attachment' to eliminate many copies of ProcDump/someprocess attachment(s) from  running?

Thanks,

@echo off
setlocal

set pd=D:\procdump.exe
set dest=D:\procdump\SomeProcessDumpDirectory
set wait=60
set keep=4
 
:_loop
set shortdatetime=%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%

cd D:\ProcDump\
START ""/min "procdump" -e -h -ma -n 20 "SomeProcessDump*.dmp" -accepteula %dest%\SomeProcessDump.dmp"
ping localhost -n %wait% > NUL 2>&1
ren "%dest%\SomeProcessServiceDump*.dmp" "%shortdatetime%.dmp"

set count=0
 
for /f "tokens=*" %%G in ('dir "%dest%\*SomeProcessServiceDump*.dmp" /a:-d /b /o:-d') do (
 set oldest=%dest%\%%G
 set /a count+=1
)
 
if %count% GTR %keep% del "%oldest%"
goto :_loop
 
if %count% GTR %keep% del "%oldest%"
goto :_loop
Someone will have an easy 500 points soon... (i think anyway if piping in a command is easy to do or if I don't figure it out first :) )

From the link below it appears in addition to piping in Ctrl-C that I will have to create another bat script to call the bat script above with the CMD /c option to prevent the above bat script from also exiting when the piped Ctrl-C is sent at each loop.

http://ss64.com/nt/cmd.html
If one batch file CALLs another batch file CTRL-C will exit both batch scripts.
If CMD /c is used to call one batch file from another then CTRL-C will cause only one of the batch scripts to terminate.
Adding below seems a valid option.  Now I will test & verify.

:holding
ping localhost -n %wait% > NUL 2>&1
FIND /I /V "SomeProcess.exe"
IF NOT ERRORLEVEL 1 GOTO :wait
IF ERRORLEVEL 1 goto :proceed

:wait
ping localhost -n %wait% > NUL 2>&1
FIND /I /V "SomeProcess.exe"
IF NOT ERRORLEVEL 1 GOTO :holding
IF ERRORLEVEL 1 goto :proceed

:proceed
if %count% GTR %keep% del "%oldest%"
goto :_loop
ASKER CERTIFIED SOLUTION
Avatar of RickJames
RickJames

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No one else helped and it was an acceptable solution to what I had originally requested
Rick,

Thanks for sharing your findings.

Cheers,
Rene