Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

bat/script file that checks for running process

Posted on 2013-01-09
6
Medium Priority
?
788 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 57

Accepted Solution

by:
Bill Prew earned 999 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Assisted Solution

by:tighec
tighec earned 501 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 57

Assisted Solution

by:Bill Prew
Bill Prew earned 999 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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