Question Locked

Script to check if service is running at interval and start if not

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'd like to write a script that checks if a service is running (routing and remote access) at an interval of say every 15 minutes and starts the service if it's not already running. I know how to start services but I'm not sure how to make something like this check on an interval timer.
I'm running SBS2003. Thanks.

4 replies

by Former member

First choice:
Windows Server 2003 Resource Kit Tools:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

Or the script (if it works):

set LOGFILE=jrun_Service.log
sc \\SERVER query spooler > LOGFILE
grep "STOPPED" LOGFILE
if not errorlevel 1 goto error

:error
net send admin SERVICE on SERVER stopped, restarting
sc \\SERVER start SERVICE
now >> POP3_service.err
echo SERVICE on SERVER stopped, restarting >> SERVER.ERR
end

Change the below variables in the script:

SERVER = The server with the POP3 Service - 3 locations in script to change
SERVICE - Name of the service to check/start - 2 locations in script to change

Save the above as a cmd file and schedule a task in schedule task to launch every hour (or thrity minutes)
.......................................

Please post back if you have any more problems or questions.
If this information is useful, please mark as helpful. Thanks.

by skone

Thanks heaps for your response.
The script all looks good, I wont be able to get a chance to test it for a few hours but I will definitely let you know if it works.

With the resource kit, what tools would I use to perform what my original post was regarding?

by Former member

"With the resource kit, what tools would I use to perform what my original post was regarding? ". It might have a few add on's. If you click on the link you will see the list of what it contains.

Hope all goes well. :)

Please post back if you have any more problems or questions.
If this information is useful, please mark as helpful. Thanks.

This discussion is closed to new replies.