Systems Management (OpenView-OP Mgmt) Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

Scheduled Task Policy

SOLVED
Go to Solution
Frequent Advisor

Scheduled Task Policy

We have a server in production that requires SQLSERVERAGENT service to be restarted exactly at 2:30am *IF* it's at stopped state. (sometimes the DBA would stop the service after hours do to some migration effort)

With that, I created and deployed a batch file with "Net Start SQLSERVERAGENT" command and uses Scheduled Task Policy to call the file at 2:30am.

However, most of the time, the service is always running, and the policy still executes itself at 2:30am (of course, it does not pose any impact nor do anything, because it has already running)

Question:

Is there a command to add to the batch file in order to tell the policy only executes at 2:30am IF the service isn't running??


big points!!

thanks!
4 REPLIES
Honored Contributor Honored Contributor

Re: Scheduled Task Policy

Hi Stan,
I would use VB script for this need.
You can use a vb script which connects to a wmi and checks if the service is running, and tries to start the service if it is not running.
HTH
Honored Contributor Honored Contributor

Re: Scheduled Task Policy

and this is a little edited version of the script i use. Run it on the node like this;

cscript checkservice.vbs

You can use a scheduled task policy again.
HTH
Highlighted
Frequent Advisor

Re: Scheduled Task Policy

I don't think this lowers the impact, but you can check the running state before in your batch file:

net start | findstr "SQLSERVERAGENT"
if %ERRORLEVEL% neq 0 net start SQLSERVERAGENT
Honored Contributor Honored Contributor

Re: Scheduled Task Policy

If you want to do with batch file itself, here is what you can try:

net start | find /i "MyServiceName"
if %errorlevel%==0 echo "service already running"

Simply "net start" will give you list of running services on the system.

HTH

Cheers!

There is nothing impossibe!