Re: Scheduled Task Policy (234 Views)
Frequent Advisor
Posts: 107
Registered: ‎04-11-2006
Message 1 of 5 (234 Views)
Accepted Solution

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)


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!!

Honored Contributor
Posts: 1,189
Registered: ‎01-09-2005
Message 2 of 5 (234 Views)

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.
Honored Contributor
Posts: 1,189
Registered: ‎01-09-2005
Message 3 of 5 (234 Views)

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.
Frequent Advisor
Posts: 29
Registered: ‎10-05-2004
Message 4 of 5 (234 Views)

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"
Honored Contributor
Posts: 711
Registered: ‎11-02-2006
Message 5 of 5 (234 Views)

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.



There is nothing impossibe!
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.