Solved

bat/script file that checks for running process

Posted on 2013-01-09
6
778 Views
Last Modified: 2013-01-24
I am a linux admin so please bare with me....

I have a Windows Server 2003 system that has been dumped in my lap until we can replace our Windows guy who recently left. This server runs a very specific application that occasionally crashes.  The problem is when this process stops it stops updating a fairly important SQL database.

What I need is a bat file, vbs script of some sort that will check if the process is running and take an action if it is not.

I would LOVE if it could send me an email if the process is not running.  This is very easy using linux but I dont know if it is as easy on Windows.  If that is not possible maybe it could just restart the process?
0
Comment
Question by:savone
6 Comments
 
LVL 1

Expert Comment

by:sarconastic
ID: 38761096
I found this script, which might be at least part of what your doing. I have used the tasklist command at the top before, it work nice to print a report of running tasks.

tasklist /FI "IMAGENAME eq notepad.exe" /FO CSV > search.log

FINDSTR notepad.exe search.log > found.log

FOR /F %%A IN (found.log) DO IF %%~zA EQU 0 GOTO end

start notepad.exe

:end

del search.log
del found.log

Open in new window


I am sure someone could come up with code to drop an email provided you have an email smtp server available.
0
 
LVL 23

Author Comment

by:savone
ID: 38761178
I do have an available SMTP server.
0
 
LVL 52

Accepted Solution

by:
Bill Prew earned 333 total points
ID: 38761631
You can shorten up the checking a bit with something like this:

tasklist /FI "IMAGENAME eq notepad.exe" | find /i "notepad" >NUL && set Found=Y || set Found=N
if "%Found% == "N" (
   REM perform logic here when not running
)

Open in new window

You can use BLAT to send an email from a BAT file, check out these links for the EXE and examples:

http://www.blat.net/
http://scripts.dragon-it.co.uk/links/email-from-batch?OpenDocument

~bp
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 2

Assisted Solution

by:tighec
tighec earned 167 total points
ID: 38762665
Slightly condensed to what is above;  tasklist combined with findstr searched for the process.
ErrorLevel is the return code, if findstr finds the process (in this case notepad.exe) it returns success (0), otherwise it returns 1.  If it reutns 1 then you can just start the server and take any other action you need, write to lo, send email etc.

tasklist |findstr "notepad.exe"
If %ERRORLEVEL% == 1 START Notepad.exe
0
 
LVL 52

Assisted Solution

by:Bill Prew
Bill Prew earned 333 total points
ID: 38762704
Or even shorter as:

tasklist | findstr "notepad.exe" > NUL || start notepad

The downside of that is that if there is a task runing called mynotepad.exe it will think notepad.exe is running, which isn't desirable.  That's what I use the search capability of the tasklist command itself to find exactly the task we want by it's name.

~bp
0
 
LVL 23

Author Closing Comment

by:savone
ID: 38815961
Not a perfect answer, but I arrived where I needed to be.

Thanks
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now