Solved

bat/script file that checks for running process

Posted on 2013-01-09
6
783 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 55

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 55

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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 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