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,
Scripting LanguagesShell ScriptingMicrosoft DOS

Avatar of undefined
Last Comment
ReneGe

8/22/2022 - Mon
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
RickJames

ASKER
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.
RickJames

ASKER
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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
RickJames

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RickJames

ASKER
No one else helped and it was an acceptable solution to what I had originally requested
ReneGe

Rick,

Thanks for sharing your findings.

Cheers,
Rene