Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Starting a dynamic list of services from a batch file.

Status
Not open for further replies.
Apr 1, 2003
7
CA
I need some help from you guys out there, I've been working on this for awhile and I am so close but I think I've been looking at it to long and the obvious is escaping me.

We have a product we sell that when installed creates a Windows service, when we install multiple systems on the same server it has a service for each installation all with different names. Normally this wouldn't be an issue but now we have quite a few installations and when the server restarts all the services try and restart at the same time bringing the server to it's knees.

To get around this what I did was created a batch file that sequentially started the services use the "net start" command. This however is also problematic because the list then needs to be maintained and the support team has proved not very good at doing this.

So what I am so close to doing now is having a batch file that will query the service manager, get me a list of services and then in a for loop start each of the services.

The problem is I have to use a 3rd party tool to remove some text from the list of services and I would like to remove this dependancy.

To get a list of services stored in a text file I run:

sc query state= all | find "JBoss" | findstr "DISPLAY_NAME STATE" > C:\JBoss.txt

This gives me a list like:

DISPLAY_NAME: JBossSOMETHINGHERE1
DISPLAY_NAME: JBossSOMETHINGHERE2

Then the 3rd party tool I use removes the text "DISPLAY_NAME:" from the file and I go into a for loop.

for /F %%a in (C:\Jboss.txt) do (
net start %%a
C:\sleep.exe 300
)

Now this does work but is there a DOS way to remove that static text so I don't have to use a 3rd party GREP tool. Or some other command that will just allow me to skip over that piece in the file.

Any help here would be greatly appreciated.
 
Did you ever get anywhere with this?

I could suggest a couple of things--

1) check out using tokens with your for statement. You would not need to remove the extra text from your output file, just pick up the second token.

2) Instead of calling net start %%a, call another batch file. netstrt %%a would expand to netstrt DISPLAY_NAME: JBossSomething.
netstrt.bat would have the one command "net start %2"

3) switch to scripting like vbscript or autoit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top