Solved

bat/script file that checks for running process

Posted on 2013-01-09
6
782 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 54

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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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 54

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

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…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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