| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
Pegasus \(MVP\)
Guest
Posts: n/a
|
*** See below.
"test" <(E-Mail Removed)> wrote in message news:26363214-a7e3-4000-932a-(E-Mail Removed)... > Greetings, > > I want to maintain (stop/start) services on remote machine in orderly > fashion. The requirement is that the next service should only be > started/stopped when previous service has stopped/started completely. > I am using Windows xp. I am able to come up with something like below: > > REM ** To stop services on remote machine ** > > start /wait sc \\server_name stop service_name1 > start /wait sc \\server_name stop service_name2 > > REM ** To start services on remote machine ** > > start /wait sc \\server_name start service_name1 > start /wait sc \\server_name start service_name2 > > > Is it true that above command means that service_name2 will only > stop/start when the first service i.e service_name1 gets > stopped/started completely? *** Probably, but if this is what you want then you should *** drop the "start" command altogether: *** sc \\Server_Name stop service_name1 > Also, I have one more issue. Sometimes when the service is getting > stopped, it goes into a "intermediate" state as STOPPING. In this > case, I want to kill this service before sc command go on stopping > next services. *** In such cases you need a loop, e.g. like so: *** *** sc \\Server_Name stop service_name1 *** :Loop1 *** ping localhost -n 10 > nul *** sc \\Server_Name query service_name1 | find /i "stopped || goto Loop1 *** *** You should also add a loop counter in order to deal *** with cases where the service can't be stopped. > Can someone please help me here. I have searched enough and not able > to come to any conclusion. > > TIA |
|
||
|
||||
|
test
Guest
Posts: n/a
|
On Feb 19, 8:20*pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> *** See below. > > "test" <harpreet.n...@gmail.com> wrote in message > > news:26363214-a7e3-4000-932a-(E-Mail Removed)... > > > > > Greetings, > > > I want to maintain (stop/start) services on remote machine in orderly > > fashion. The requirement is that the next service should only be > > started/stopped when previous service has stopped/started completely. > > I am using Windows xp. I am able to come up with something like below: > > > REM ** To stop services on remote machine ** > > > start /wait sc \\server_name stop service_name1 > > start /wait sc \\server_name stop service_name2 > > > REM ** To start services on remote machine ** > > > start /wait sc \\server_name start service_name1 > > start /wait sc \\server_name start service_name2 > > > Is it true that above command means that service_name2 will only > > stop/start when the first service i.e service_name1 gets > > stopped/started completely? > > *** Probably, but if this is what you want then you should > *** drop the "start" command altogether: > *** sc \\Server_Name stop service_name1 > > > Also, I have one more issue. Sometimes when the service is getting > > stopped, it goes into a "intermediate" state as STOPPING. In this > > case, I want to kill this service before sc command go on stopping > > next services. > > *** In such cases you need a loop, e.g. like so: > *** > *** sc \\Server_Name stop service_name1 > *** :Loop1 > *** ping localhost -n 10 > nul > *** sc \\Server_Name query service_name1 | find /i "stopped || goto Loop1 > *** > *** You should also add a loop counter in order to deal > *** with cases where the service can't be stopped. > > > > > Can someone please help me here. I have searched enough and not able > > to come to any conclusion. > > > TIA- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - Thanks. But the requirement says that I have to stop certain services (stop next service only when previous service has completely stopped) and then start them in reverse order (again, the next service should be started only when previous services has started completely). So based on your inputs I was able to modify the code as below REM ** stopping first service sc \\server_name stop service_name1 REM ** looping to make sure service got completely stopped ** :Loop1 ping localhost -n 10 > nul sc \\server_name query service_name | find /i "stopped" || goto Loop1 Does the loop breaks when it finds "stopped" status for a particular service? if yes, this takes care of the requirement where I need to make sure that I will only proceed further when previous service in STOPPED status. But how will I kill this service if it gets stuck in STOPPING status? I mean in my case some services do get stuck in STOPPING status and we have to manually killl it right away. How can I check if the service got stuck in STOPPING status and how should I kill it? Also, the above loop make sure that we proceed only when previous service has completely stopped. Correct me, but I thought even the following two commands also does the same job. I mean the following sc command (using wait) parameter, makes sure that next service is only started/stopped, when the current service has been completely started/ stopped. Is it not the case? I mean what does wait parameter mean here? start /wait sc \\server_name stop service_name1 start /wait sc \\server_name stop service_name2 TIA |
|
||
|
||||
|
Pegasus \(MVP\)
Guest
Posts: n/a
|
"test" <(E-Mail Removed)> wrote in message news:56c0caf6-c6c2-4e4f-b108-(E-Mail Removed)... On Feb 19, 8:20 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > *** See below. > > "test" <harpreet.n...@gmail.com> wrote in message > > news:26363214-a7e3-4000-932a-(E-Mail Removed)... > > > > > Greetings, > > > I want to maintain (stop/start) services on remote machine in orderly > > fashion. The requirement is that the next service should only be > > started/stopped when previous service has stopped/started completely. > > I am using Windows xp. I am able to come up with something like below: > > > REM ** To stop services on remote machine ** > > > start /wait sc \\server_name stop service_name1 > > start /wait sc \\server_name stop service_name2 > > > REM ** To start services on remote machine ** > > > start /wait sc \\server_name start service_name1 > > start /wait sc \\server_name start service_name2 > > > Is it true that above command means that service_name2 will only > > stop/start when the first service i.e service_name1 gets > > stopped/started completely? > > *** Probably, but if this is what you want then you should > *** drop the "start" command altogether: > *** sc \\Server_Name stop service_name1 > > > Also, I have one more issue. Sometimes when the service is getting > > stopped, it goes into a "intermediate" state as STOPPING. In this > > case, I want to kill this service before sc command go on stopping > > next services. > > *** In such cases you need a loop, e.g. like so: > *** > *** sc \\Server_Name stop service_name1 > *** :Loop1 > *** ping localhost -n 10 > nul > *** sc \\Server_Name query service_name1 | find /i "stopped || goto Loop1 > *** > *** You should also add a loop counter in order to deal > *** with cases where the service can't be stopped. > > > > > Can someone please help me here. I have searched enough and not able > > to come to any conclusion. > > > TIA- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - Thanks. But the requirement says that I have to stop certain services (stop next service only when previous service has completely stopped) and then start them in reverse order (again, the next service should be started only when previous services has started completely). So based on your inputs I was able to modify the code as below REM ** stopping first service sc \\server_name stop service_name1 REM ** looping to make sure service got completely stopped ** :Loop1 ping localhost -n 10 > nul sc \\server_name query service_name | find /i "stopped" || goto Loop1 Does the loop breaks when it finds "stopped" status for a particular service? if yes, this takes care of the requirement where I need to make sure that I will only proceed further when previous service in STOPPED status. *** The || connector will cause the subsequent command *** ("goto Loop1") to be executed if and only if sc.exe does *** not output the word "stopped". What do YOU think will *** happen when sc.exe does output the word "stopped"? But how will I kill this service if it gets stuck in STOPPING status? I mean in my case some services do get stuck in STOPPING status and we have to manually killl it right away. How can I check if the service got stuck in STOPPING status and how should I kill it? *** Best for you to become familiar with some basic loop *** commands. Try this little batch file, then adapt it to your *** current problem: *** @echo off *** set count=0 *** :Label1 *** set /a count=%count% + 1 *** if %count% LSS 10 goto Label1 *** echo Count is now %count% *** *** I could, of course, give you a turn-key solution. On the other *** hand I think that it will be to your benefit if you really *** understand what your batch files do. Also, the above loop make sure that we proceed only when previous service has completely stopped. Correct me, but I thought even the following two commands also does the same job. I mean the following sc command (using wait) parameter, makes sure that next service is only started/stopped, when the current service has been completely started/ stopped. Is it not the case? I mean what does wait parameter mean here? start /wait sc \\server_name stop service_name1 start /wait sc \\server_name stop service_name2 *** The "/wait" parameter relates to the start command. It causes *** the start command to wait until sc.exe returns control. This *** often happens a long time before the service is stopped. TIA |
|
||
|
||||
|
test
Guest
Posts: n/a
|
On Feb 19, 9:33*pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "test" <harpreet.n...@gmail.com> wrote in message > > news:56c0caf6-c6c2-4e4f-b108-(E-Mail Removed)... > On Feb 19, 8:20 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > > > > *** See below. > > > "test" <harpreet.n...@gmail.com> wrote in message > > >news:26363214-a7e3-4000-932a-(E-Mail Removed).... > > > > Greetings, > > > > I want to maintain (stop/start) services on remote machine in orderly > > > fashion. The requirement is that the next service should only be > > > started/stopped when previous service has stopped/started completely. > > > I am using Windows xp. I am able to come up with something like below: > > > > REM ** To stop services on remote machine ** > > > > start /wait sc \\server_name stop service_name1 > > > start /wait sc \\server_name stop service_name2 > > > > REM ** To start services on remote machine ** > > > > start /wait sc \\server_name start service_name1 > > > start /wait sc \\server_name start service_name2 > > > > Is it true that above command means that service_name2 will only > > > stop/start when the first service i.e service_name1 gets > > > stopped/started completely? > > > *** Probably, but if this is what you want then you should > > *** drop the "start" command altogether: > > *** sc \\Server_Name stop service_name1 > > > > Also, I have one more issue. Sometimes when the service is getting > > > stopped, it goes into a "intermediate" state as STOPPING. In this > > > case, I want to kill this service before sc command go on stopping > > > next services. > > > *** In such cases you need a loop, e.g. like so: > > *** > > *** sc \\Server_Name stop service_name1 > > *** :Loop1 > > *** ping localhost -n 10 > nul > > *** sc \\Server_Name query service_name1 | find /i "stopped || goto Loop1 > > *** > > *** You should also add a loop counter in order to deal > > *** with cases where the service can't be stopped. > > > > Can someone please help me here. I have searched enough and not able > > > to come to any conclusion. > > > > TIA- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text - > > Thanks. But the requirement says that I have to stop certain services > (stop next service only when previous service has completely stopped) > and then start them in reverse order (again, the next service should > be started only when previous services has started completely). > > So based on your inputs I was able to modify the code as below > > REM ** stopping first service > sc \\server_name stop service_name1 > > REM ** looping to make sure service got completely stopped ** > > :Loop1 > ping localhost -n 10 > nul > sc \\server_name query service_name | find /i "stopped" || goto Loop1 > > Does the loop breaks when it finds "stopped" status for a particular > service? if yes, this takes care of the requirement where I need to > make sure that I will only proceed further when previous service in > STOPPED status. > *** The || connector will cause the subsequent command > *** ("goto Loop1") to be executed if and only if sc.exe does > *** not output the word "stopped". What do YOU think will > *** happen when sc.exe does output the word "stopped"? > > But how will I kill this service if it gets stuck in > STOPPING status? I mean in my case some services do get stuck in > STOPPING status and we have to manually killl it right away. How can I > check if the service got stuck in STOPPING status and how should I > kill it? > > *** Best for you to become familiar with some basic loop > *** commands. Try this little batch file, then adapt it to your > *** current problem: > *** @echo off > *** set count=0 > *** :Label1 > *** set /a count=%count% + 1 > *** if %count% LSS 10 goto Label1 > *** echo Count is now %count% > *** > *** I could, of course, give you a turn-key solution. On the other > *** hand I think that it will be to your benefit if you really > *** understand what your batch files do. > > Also, the above loop make sure that we proceed only when previous > service has completely stopped. Correct me, but I thought even the > following two commands also does the same job. I mean the following sc > command (using wait) parameter, makes sure that next service is only > started/stopped, when the current service has been completely started/ > stopped. Is it not the case? I mean what does wait parameter mean > here? > > start /wait sc \\server_name stop service_name1 > start /wait sc \\server_name stop service_name2 > *** The "/wait" parameter relates to the start command. It causes > *** the start command to wait until sc.exe returns control. This > *** often happens a long time before the service is stopped. > > TIA- Hide quoted text - > > - Show quoted text - Thanks again Pegasus. Well as far as the loop is concerned, the control will break out of the loop when it encounters "stopped". One question, I just tried below command start /wait sc \\server_name stop service_name1 start /wait sc \\server_name stop service_name2 Both services went in "starting" status at the same time. I also checked logs of both services on servername and it seems both have same start time. My question, is why the two services went in "starting" status at the same time? I thought the "wait" parameter will halt processing of next service until the current command terminates? Also, logs shows the same start time for both services. Is this expected? TIA |
|
||
|
||||
|
Pegasus \(MVP\)
Guest
Posts: n/a
|
"test" <(E-Mail Removed)> wrote in message news:0f76bbc5-b8b9-4726-9078-(E-Mail Removed)... On Feb 19, 9:33 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > "test" <harpreet.n...@gmail.com> wrote in message > > news:56c0caf6-c6c2-4e4f-b108-(E-Mail Removed)... > On Feb 19, 8:20 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > > > > *** See below. > > > "test" <harpreet.n...@gmail.com> wrote in message > > >news:26363214-a7e3-4000-932a-(E-Mail Removed)... > > > > Greetings, > > > > I want to maintain (stop/start) services on remote machine in orderly > > > fashion. The requirement is that the next service should only be > > > started/stopped when previous service has stopped/started completely. > > > I am using Windows xp. I am able to come up with something like below: > > > > REM ** To stop services on remote machine ** > > > > start /wait sc \\server_name stop service_name1 > > > start /wait sc \\server_name stop service_name2 > > > > REM ** To start services on remote machine ** > > > > start /wait sc \\server_name start service_name1 > > > start /wait sc \\server_name start service_name2 > > > > Is it true that above command means that service_name2 will only > > > stop/start when the first service i.e service_name1 gets > > > stopped/started completely? > > > *** Probably, but if this is what you want then you should > > *** drop the "start" command altogether: > > *** sc \\Server_Name stop service_name1 > > > > Also, I have one more issue. Sometimes when the service is getting > > > stopped, it goes into a "intermediate" state as STOPPING. In this > > > case, I want to kill this service before sc command go on stopping > > > next services. > > > *** In such cases you need a loop, e.g. like so: > > *** > > *** sc \\Server_Name stop service_name1 > > *** :Loop1 > > *** ping localhost -n 10 > nul > > *** sc \\Server_Name query service_name1 | find /i "stopped || goto > > Loop1 > > *** > > *** You should also add a loop counter in order to deal > > *** with cases where the service can't be stopped. > > > > Can someone please help me here. I have searched enough and not able > > > to come to any conclusion. > > > > TIA- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text - > > Thanks. But the requirement says that I have to stop certain services > (stop next service only when previous service has completely stopped) > and then start them in reverse order (again, the next service should > be started only when previous services has started completely). > > So based on your inputs I was able to modify the code as below > > REM ** stopping first service > sc \\server_name stop service_name1 > > REM ** looping to make sure service got completely stopped ** > > :Loop1 > ping localhost -n 10 > nul > sc \\server_name query service_name | find /i "stopped" || goto Loop1 > > Does the loop breaks when it finds "stopped" status for a particular > service? if yes, this takes care of the requirement where I need to > make sure that I will only proceed further when previous service in > STOPPED status. > *** The || connector will cause the subsequent command > *** ("goto Loop1") to be executed if and only if sc.exe does > *** not output the word "stopped". What do YOU think will > *** happen when sc.exe does output the word "stopped"? > > But how will I kill this service if it gets stuck in > STOPPING status? I mean in my case some services do get stuck in > STOPPING status and we have to manually killl it right away. How can I > check if the service got stuck in STOPPING status and how should I > kill it? > > *** Best for you to become familiar with some basic loop > *** commands. Try this little batch file, then adapt it to your > *** current problem: > *** @echo off > *** set count=0 > *** :Label1 > *** set /a count=%count% + 1 > *** if %count% LSS 10 goto Label1 > *** echo Count is now %count% > *** > *** I could, of course, give you a turn-key solution. On the other > *** hand I think that it will be to your benefit if you really > *** understand what your batch files do. > > Also, the above loop make sure that we proceed only when previous > service has completely stopped. Correct me, but I thought even the > following two commands also does the same job. I mean the following sc > command (using wait) parameter, makes sure that next service is only > started/stopped, when the current service has been completely started/ > stopped. Is it not the case? I mean what does wait parameter mean > here? > > start /wait sc \\server_name stop service_name1 > start /wait sc \\server_name stop service_name2 > *** The "/wait" parameter relates to the start command. It causes > *** the start command to wait until sc.exe returns control. This > *** often happens a long time before the service is stopped. > > TIA- Hide quoted text - > > - Show quoted text - Thanks again Pegasus. Well as far as the loop is concerned, the control will break out of the loop when it encounters "stopped". One question, I just tried below command start /wait sc \\server_name stop service_name1 start /wait sc \\server_name stop service_name2 Both services went in "starting" status at the same time. I also checked logs of both services on servername and it seems both have same start time. My question, is why the two services went in "starting" status at the same time? I thought the "wait" parameter will halt processing of next service until the current command terminates? Also, logs shows the same start time for both services. Is this expected? ================ Yes, it is fully expected. I mentioned before that you should drop the "start" command. If you don't then you get exactly what you got here. |
|
||
|
||||
|
test
Guest
Posts: n/a
|
On Feb 20, 5:45*pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "test" <harpreet.n...@gmail.com> wrote in message > > news:0f76bbc5-b8b9-4726-9078-(E-Mail Removed)... > On Feb 19, 9:33 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > > > > "test" <harpreet.n...@gmail.com> wrote in message > > >news:56c0caf6-c6c2-4e4f-b108-(E-Mail Removed).... > > On Feb 19, 8:20 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > *** See below. > > > > "test" <harpreet.n...@gmail.com> wrote in message > > > >news:26363214-a7e3-4000-932a-(E-Mail Removed).... > > > > > Greetings, > > > > > I want to maintain (stop/start) services on remote machine in orderly > > > > fashion. The requirement is that the next service should only be > > > > started/stopped when previous service has stopped/started completely. > > > > I am using Windows xp. I am able to come up with something like below: > > > > > REM ** To stop services on remote machine ** > > > > > start /wait sc \\server_name stop service_name1 > > > > start /wait sc \\server_name stop service_name2 > > > > > REM ** To start services on remote machine ** > > > > > start /wait sc \\server_name start service_name1 > > > > start /wait sc \\server_name start service_name2 > > > > > Is it true that above command means that service_name2 will only > > > > stop/start when the first service i.e service_name1 gets > > > > stopped/started completely? > > > > *** Probably, but if this is what you want then you should > > > *** drop the "start" command altogether: > > > *** sc \\Server_Name stop service_name1 > > > > > Also, I have one more issue. Sometimes when the service is getting > > > > stopped, it goes into a "intermediate" state as STOPPING. In this > > > > case, I want to kill this service before sc command go on stopping > > > > next services. > > > > *** In such cases you need a loop, e.g. like so: > > > *** > > > *** sc \\Server_Name stop service_name1 > > > *** :Loop1 > > > *** ping localhost -n 10 > nul > > > *** sc \\Server_Name query service_name1 | find /i "stopped || goto > > > Loop1 > > > *** > > > *** You should also add a loop counter in order to deal > > > *** with cases where the service can't be stopped. > > > > > Can someone please help me here. I have searched enough and not able > > > > to come to any conclusion. > > > > > TIA- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > > > Thanks. But the requirement says that I have to stop certain services > > (stop next service only when previous service has completely stopped) > > and then start them in reverse order (again, the next service should > > be started only when previous services has started completely). > > > So based on your inputs I was able to modify the code as below > > > REM ** stopping first service > > sc \\server_name stop service_name1 > > > REM ** looping to make sure service got completely stopped ** > > > :Loop1 > > ping localhost -n 10 > nul > > sc \\server_name query service_name | find /i "stopped" || goto Loop1 > > > Does the loop breaks when it finds "stopped" status for a particular > > service? if yes, this takes care of the requirement where I need to > > make sure that I will only proceed further when previous service in > > STOPPED status. > > *** The || connector will cause the subsequent command > > *** ("goto Loop1") to be executed if and only if sc.exe does > > *** not output the word "stopped". What do YOU think will > > *** happen when sc.exe does output the word "stopped"? > > > But how will I kill this service if it gets stuck in > > STOPPING status? I mean in my case some services do get stuck in > > STOPPING status and we have to manually killl it right away. How can I > > check if the service got stuck in STOPPING status and how should I > > kill it? > > > *** Best for you to become familiar with some basic loop > > *** commands. Try this little batch file, then adapt it to your > > *** current problem: > > *** @echo off > > *** set count=0 > > *** :Label1 > > *** set /a count=%count% + 1 > > *** if %count% LSS 10 goto Label1 > > *** echo Count is now %count% > > *** > > *** I could, of course, give you a turn-key solution. On the other > > *** hand I think that it will be to your benefit if you really > > *** understand what your batch files do. > > > Also, the above loop make sure that we proceed only when previous > > service has completely stopped. Correct me, but I thought even the > > following two commands also does the same job. I mean the following sc > > command (using wait) parameter, makes sure that next service is only > > started/stopped, when the current service has been completely started/ > > stopped. Is it not the case? I mean what does wait parameter mean > > here? > > > start /wait sc \\server_name stop service_name1 > > start /wait sc \\server_name stop service_name2 > > *** The "/wait" parameter relates to the start command. It causes > > *** the start command to wait until sc.exe returns control. This > > *** often happens a long time before the service is stopped. > > > TIA- Hide quoted text - > > > - Show quoted text - > > Thanks again Pegasus. Well as far as the loop is concerned, the > control will break out of the loop when it encounters "stopped". One > question, I just tried below command > > start /wait sc \\server_name stop service_name1 > start /wait sc \\server_name stop service_name2 > > Both services went in "starting" status at the same time. I also > checked logs of both services on servername and it seems both have > same start time. My question, is why the two services went in > "starting" status at the same time? I thought the "wait" parameter > will halt processing of next service until the current command > terminates? Also, logs shows the same start time for both services. Is > this expected? > > ================ > > Yes, it is fully expected. I mentioned before that you should drop the > "start" command. If you don't then you get exactly what you got here.- Hide quoted text - > > - Show quoted text - Thanks for the reply Pegasus. So I am able to come up with below code REM service_names.txt contains all service names REM This code is for starting services one after other FOR /F %%i IN (service_names.txt) DO ( set servicename=%%i sc \\server_name start !servicename! :Loop1 ping localhost -n 5 > nul sc query !servicename! | find /i "running" || goto Loop1 echo !servicename! started successfully. ) One question, is there still a way that this can be done using wait option. Wherever I am reading about wait, it says it halts any further processing until the current command is terminated. So isnt it same as what we are doing in the above code? Sorry but I still had this doubt. Also at the end, I would like to send out a notification mail to respective recipients. I cannot use any third party tool. I tried mailto command but it opens up a new mail in outlook with respective subject but does not send it. Why cant it send it automatically to respective recipients? Can you, again, help me here. I do not want to attach any files. Just a simple mail to 2-3 recipients with a subject something like "serivces started successfully". TIA |
|
||
|
||||
|
Pegasus \(MVP\)
Guest
Posts: n/a
|
"test" <(E-Mail Removed)> wrote in message news:21e8f707-7c5e-4ec1-b60b-(E-Mail Removed)... On Feb 20, 5:45 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > "test" <harpreet.n...@gmail.com> wrote in message > > news:0f76bbc5-b8b9-4726-9078-(E-Mail Removed)... > On Feb 19, 9:33 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > > > > "test" <harpreet.n...@gmail.com> wrote in message > > >news:56c0caf6-c6c2-4e4f-b108-(E-Mail Removed)... > > On Feb 19, 8:20 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > *** See below. > > > > "test" <harpreet.n...@gmail.com> wrote in message > > > >news:26363214-a7e3-4000-932a-(E-Mail Removed)... > > > > > Greetings, > > > > > I want to maintain (stop/start) services on remote machine in > > > > orderly > > > > fashion. The requirement is that the next service should only be > > > > started/stopped when previous service has stopped/started > > > > completely. > > > > I am using Windows xp. I am able to come up with something like > > > > below: > > > > > REM ** To stop services on remote machine ** > > > > > start /wait sc \\server_name stop service_name1 > > > > start /wait sc \\server_name stop service_name2 > > > > > REM ** To start services on remote machine ** > > > > > start /wait sc \\server_name start service_name1 > > > > start /wait sc \\server_name start service_name2 > > > > > Is it true that above command means that service_name2 will only > > > > stop/start when the first service i.e service_name1 gets > > > > stopped/started completely? > > > > *** Probably, but if this is what you want then you should > > > *** drop the "start" command altogether: > > > *** sc \\Server_Name stop service_name1 > > > > > Also, I have one more issue. Sometimes when the service is getting > > > > stopped, it goes into a "intermediate" state as STOPPING. In this > > > > case, I want to kill this service before sc command go on stopping > > > > next services. > > > > *** In such cases you need a loop, e.g. like so: > > > *** > > > *** sc \\Server_Name stop service_name1 > > > *** :Loop1 > > > *** ping localhost -n 10 > nul > > > *** sc \\Server_Name query service_name1 | find /i "stopped || goto > > > Loop1 > > > *** > > > *** You should also add a loop counter in order to deal > > > *** with cases where the service can't be stopped. > > > > > Can someone please help me here. I have searched enough and not able > > > > to come to any conclusion. > > > > > TIA- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > > > Thanks. But the requirement says that I have to stop certain services > > (stop next service only when previous service has completely stopped) > > and then start them in reverse order (again, the next service should > > be started only when previous services has started completely). > > > So based on your inputs I was able to modify the code as below > > > REM ** stopping first service > > sc \\server_name stop service_name1 > > > REM ** looping to make sure service got completely stopped ** > > > :Loop1 > > ping localhost -n 10 > nul > > sc \\server_name query service_name | find /i "stopped" || goto Loop1 > > > Does the loop breaks when it finds "stopped" status for a particular > > service? if yes, this takes care of the requirement where I need to > > make sure that I will only proceed further when previous service in > > STOPPED status. > > *** The || connector will cause the subsequent command > > *** ("goto Loop1") to be executed if and only if sc.exe does > > *** not output the word "stopped". What do YOU think will > > *** happen when sc.exe does output the word "stopped"? > > > But how will I kill this service if it gets stuck in > > STOPPING status? I mean in my case some services do get stuck in > > STOPPING status and we have to manually killl it right away. How can I > > check if the service got stuck in STOPPING status and how should I > > kill it? > > > *** Best for you to become familiar with some basic loop > > *** commands. Try this little batch file, then adapt it to your > > *** current problem: > > *** @echo off > > *** set count=0 > > *** :Label1 > > *** set /a count=%count% + 1 > > *** if %count% LSS 10 goto Label1 > > *** echo Count is now %count% > > *** > > *** I could, of course, give you a turn-key solution. On the other > > *** hand I think that it will be to your benefit if you really > > *** understand what your batch files do. > > > Also, the above loop make sure that we proceed only when previous > > service has completely stopped. Correct me, but I thought even the > > following two commands also does the same job. I mean the following sc > > command (using wait) parameter, makes sure that next service is only > > started/stopped, when the current service has been completely started/ > > stopped. Is it not the case? I mean what does wait parameter mean > > here? > > > start /wait sc \\server_name stop service_name1 > > start /wait sc \\server_name stop service_name2 > > *** The "/wait" parameter relates to the start command. It causes > > *** the start command to wait until sc.exe returns control. This > > *** often happens a long time before the service is stopped. > > > TIA- Hide quoted text - > > > - Show quoted text - > > Thanks again Pegasus. Well as far as the loop is concerned, the > control will break out of the loop when it encounters "stopped". One > question, I just tried below command > > start /wait sc \\server_name stop service_name1 > start /wait sc \\server_name stop service_name2 > > Both services went in "starting" status at the same time. I also > checked logs of both services on servername and it seems both have > same start time. My question, is why the two services went in > "starting" status at the same time? I thought the "wait" parameter > will halt processing of next service until the current command > terminates? Also, logs shows the same start time for both services. Is > this expected? > > ================ > > Yes, it is fully expected. I mentioned before that you should drop the > "start" command. If you don't then you get exactly what you got here.- > Hide quoted text - > > - Show quoted text - Thanks for the reply Pegasus. So I am able to come up with below code REM service_names.txt contains all service names REM This code is for starting services one after other FOR /F %%i IN (service_names.txt) DO ( set servicename=%%i sc \\server_name start !servicename! :Loop1 ping localhost -n 5 > nul sc query !servicename! | find /i "running" || goto Loop1 echo !servicename! started successfully. ) One question, is there still a way that this can be done using wait option. Wherever I am reading about wait, it says it halts any further processing until the current command is terminated. So isnt it same as what we are doing in the above code? Sorry but I still had this doubt. Also at the end, I would like to send out a notification mail to respective recipients. I cannot use any third party tool. I tried mailto command but it opens up a new mail in outlook with respective subject but does not send it. Why cant it send it automatically to respective recipients? Can you, again, help me here. I do not want to attach any files. Just a simple mail to 2-3 recipients with a subject something like "serivces started successfully". TIA ====================== I would simplify the batch file a little, e.g. like so: @echo off REM service_names.txt contains all service names REM This code is for starting services one after other FOR /F %%i IN (service_names.txt) DO ( sc \\server_name start %%i :Loop1 ping localhost -n 5 > nul sc query %%i | find /i "running" || goto Loop1 echo %%i started successfully. ) As you see, there is no need for the "EnableDelayedExpansion" statement. If you tell your son: "No TV watching until you've done your homework" then you either believe him when he says that he's finished or else you check it yourself. It's the same with sc.exe: If it terminates without finishing its job then the "Start" command can do nothing at all about it, regardless of the /wait parameter. It's YOUR responsibility to check the status of the service to be stopped. You can use this batch file to send an EMail message: @echo off set sender=(E-Mail Removed) set receiver=(E-Mail Removed) set server=mail.company.com set subject=Test Mail set body=The quick brown fox set schema=http://schemas.microsoft.com/cdo/configuration/ set scr=c:\TempVBS.VBS echo> %scr% Set objEmail = CreateObject("CDO.Message") echo>>%scr% With objEmail echo>>%scr% .From = "%sender%" echo>>%scr% .To = "%receiver%" echo>>%scr% .Subject = "%subject%" echo>>%scr% .Textbody = "%body%" echo>>%scr% With .Configuration.Fields echo>>%scr% .Item ("%schema%" ^& "sendusing") = 2 echo>>%scr% .Item ("%schema%" ^& "smtpserver") = "%server%" echo>>%scr% .Item ("%schema%" ^& "smtpserverport") = 25 echo>>%scr% .Item ("%schema%" ^& "smtpauthenticate") = cdoBasic echo>>%scr% .Item ("%schema%" ^& "sendusername") = "%sender%" echo>>%scr% End With echo>>%scr% .Configuration.Fields.Update echo>>%scr% .Send echo>>%scr% End With cscript //nologo %scr% del %scr% |
|
||
|
||||
|
test
Guest
Posts: n/a
|
On Feb 20, 9:41*pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "test" <harpreet.n...@gmail.com> wrote in message > > news:21e8f707-7c5e-4ec1-b60b-(E-Mail Removed)... > On Feb 20, 5:45 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > > > > "test" <harpreet.n...@gmail.com> wrote in message > > >news:0f76bbc5-b8b9-4726-9078-(E-Mail Removed).... > > On Feb 19, 9:33 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > "test" <harpreet.n...@gmail.com> wrote in message > > > >news:56c0caf6-c6c2-4e4f-b108-(E-Mail Removed).... > > > On Feb 19, 8:20 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote: > > > > > *** See below. > > > > > "test" <harpreet.n...@gmail.com> wrote in message > > > > >news:26363214-a7e3-4000-932a-(E-Mail Removed)... > > > > > > Greetings, > > > > > > I want to maintain (stop/start) services on remote machine in > > > > > orderly > > > > > fashion. The requirement is that the next service should only be > > > > > started/stopped when previous service has stopped/started > > > > > completely. > > > > > I am using Windows xp. I am able to come up with something like > > > > > below: > > > > > > REM ** To stop services on remote machine ** > > > > > > start /wait sc \\server_name stop service_name1 > > > > > start /wait sc \\server_name stop service_name2 > > > > > > REM ** To start services on remote machine ** > > > > > > start /wait sc \\server_name start service_name1 > > > > > start /wait sc \\server_name start service_name2 > > > > > > Is it true that above command means that service_name2 will only > > > > > stop/start when the first service i.e service_name1 gets > > > > > stopped/started completely? > > > > > *** Probably, but if this is what you want then you should > > > > *** drop the "start" command altogether: > > > > *** sc \\Server_Name stop service_name1 > > > > > > Also, I have one more issue. Sometimes when the service is getting > > > > > stopped, it goes into a "intermediate" state as STOPPING. In this > > > > > case, I want to kill this service before sc command go on stopping > > > > > next services. > > > > > *** In such cases you need a loop, e.g. like so: > > > > *** > > > > *** sc \\Server_Name stop service_name1 > > > > *** :Loop1 > > > > *** ping localhost -n 10 > nul > > > > *** sc \\Server_Name query service_name1 | find /i "stopped || goto > > > > Loop1 > > > > *** > > > > *** You should also add a loop counter in order to deal > > > > *** with cases where the service can't be stopped. > > > > > > Can someone please help me here. I have searched enough and not able > > > > > to come to any conclusion. > > > > > > TIA- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > > > - Show quoted text - > > > > Thanks. But the requirement says that I have to stop certain services > > > (stop next service only when previous service has completely stopped) > > > and then start them in reverse order (again, the next service should > > > be started only when previous services has started completely). > > > > So based on your inputs I was able to modify the code as below > > > > REM ** stopping first service > > > sc \\server_name stop service_name1 > > > > REM ** looping to make sure service got completely stopped ** > > > > :Loop1 > > > ping localhost -n 10 > nul > > > sc \\server_name query service_name | find /i "stopped" || goto Loop1 > > > > Does the loop breaks when it finds "stopped" status for a particular > > > service? if yes, this takes care of the requirement where I need to > > > make sure that I will only proceed further when previous service in > > > STOPPED status. > > > *** The || connector will cause the subsequent command > > > *** ("goto Loop1") to be executed if and only if sc.exe does > > > *** not output the word "stopped". What do YOU think will > > > *** happen when sc.exe does output the word "stopped"? > > > > But how will I kill this service if it gets stuck in > > > STOPPING status? I mean in my case some services do get stuck in > > > STOPPING status and we have to manually killl it right away. How can I > > > check if the service got stuck in STOPPING status and how should I > > > kill it? > > > > *** Best for you to become familiar with some basic loop > > > *** commands. Try this littlebatchfile, then adapt it to your > > > *** current problem: > > > *** @echo off > > > *** set count=0 > > > *** :Label1 > > > *** set /a count=%count% + 1 > > > *** if %count% LSS 10 goto Label1 > > > *** echo Count is now %count% > > > *** > > > *** I could, of course, give you a turn-key solution. On the other > > > *** hand I think that it will be to your benefit if you really > > > *** understand what yourbatchfiles do. > > > > Also, the above loop make sure that we proceed only when previous > > > service has completely stopped. Correct me, but I thought even the > > > following two commands also does the same job. I mean the following sc > > > command (using wait) parameter, makes sure that next service is only > > > started/stopped, when the current service has been completely started/ > > > stopped. Is it not the case? I mean what does wait parameter mean > > > here? > > > > start /wait sc \\server_name stop service_name1 > > > start /wait sc \\server_name stop service_name2 > > > *** The "/wait" parameter relates to the start command. It causes > > > *** the start command to wait until sc.exe returns control. This > > > *** often happens a long time before the service is stopped. > > > > TIA- Hide quoted text - > > > > - Show quoted text - > > > Thanks again Pegasus. Well as far as the loop is concerned, the > > control will break out of the loop when it encounters "stopped". One > > question, I just tried below command > > > start /wait sc \\server_name stop service_name1 > > start /wait sc \\server_name stop service_name2 > > > Both services went in "starting" status at the same time. I also > > checked logs of both services on servername and it seems both have > > same start time. My question, is why the two services went in > > "starting" status at the same time? I thought the "wait" parameter > > will halt processing of next service until the current command > > terminates? Also, logs shows the same start time for both services. Is > > this expected? > > > ================ > > > Yes, it is fully expected. I mentioned before that you should drop the > > "start" command. If you don't then you get exactly what you got here.- > > Hide quoted text - > > > - Show quoted text - > > Thanks for the reply Pegasus. So I am able to come up with below code > > REM service_names.txt contains all service names > REM This code is for starting services one after other > > FOR /F %%i IN (service_names.txt) DO ( > set servicename=%%i > > sc \\server_name start !servicename! > > :Loop1 > ping localhost -n 5 > nul > sc query !servicename! | find /i "running" || goto Loop1 > > echo !servicename! started successfully. > > ) > > One question, is there still a way that this can be done using wait > option. Wherever I am reading about wait, it says it halts any further > processing until the current command is terminated. So isnt it same as > what we are doing in the above code? Sorry but I still had this > doubt. > > Also at the end, I would like to send out a notification mail to > respective recipients. I cannot use any third party tool. I tried > mailto command but it opens up a new mail in outlook with respective > subject but does not send it. Why cant it send it automatically to > respective recipients? Can you, again, help me here. I do not want to > attach any files. Just a simple *mail to 2-3 recipients with a subject > something like "serivces started successfully". > > TIA > > ====================== > I would simplify thebatchfile a little, e.g. like so: > @echo off > REM service_names.txt contains all service names > REM This code is for starting services one after other > > FOR /F %%i IN (service_names.txt) DO ( > * sc \\server_name start %%i > > :Loop1 > * ping localhost -n 5 > nul > * sc query %%i | find /i "running" || goto Loop1 > > * echo %%i started successfully. > ) > > As you see, there is no need for the "EnableDelayedExpansion" statement. > > If you tell your son: "No TV watching until you've done your homework" then > you either believe him when he says that he's finished or else you check it > yourself. It's the same with sc.exe: If it terminates without finishing its > job then the "Start" command can do nothing at all about it, regardless of > the /wait parameter. It's YOUR responsibility to check the status of the > service to be stopped. > > You can use thisbatchfile to send an EMail message: > @echo off > set sender=...@company.com > set receiver=j...@company.com > set server=mail.company.com > set subject=Test Mail > set body=The quick brown fox > > set schema=http://schemas.microsoft.com/cdo/configuration/ > set scr=c:\TempVBS.VBS > echo> %scr% Set objEmail = CreateObject("CDO.Message") > echo>>%scr% With objEmail > echo>>%scr% *.From = "%sender%" > echo>>%scr% *.To = "%receiver%" > echo>>%scr% *.Subject = "%subject%" > echo>>%scr% *.Textbody = "%body%" > echo>>%scr% *With .Configuration.Fields > echo>>%scr% * .Item ("%schema%" ^& "sendusing") = 2 > echo>>%scr% * .Item ("%schema%" ^& "smtpserver") = "%server%" > echo>>%scr% * .Item ("%schema%" ^& "smtpserverport") = 25 > echo>>%scr% * .Item ("%schema%" ^& "smtpauthenticate") = cdoBasic > echo>>%scr% * .Item ("%schema%" ^& "sendusername") = "%sender%" > echo>>%scr% *End With > echo>>%scr% *.Configuration.Fields.Update > echo>>%scr% *.Send > echo>>%scr% End With > cscript //nologo %scr% > del %scr%- Hide quoted text - > > - Show quoted text - Thanks again Pegasus. I am now using your suggestion and not including "EnableDelayedExpansion" statement. Its working as expected. I tried the above code but got following error: C:\Documents and Settings\dir1\dir2\TempVBS.VBS(15, 2) CDO.Message.1: The "SendUsing" configuration value is invalid. I tried searching on this error but could not find on what value I should change "sendusing" value to. Can you please advise. Also, as far as killing of services is concerned, I was able to come up with following code. Just wanted to have your suggestion this.: Each service is stopped and a delay is given after which the service's status is checked. If service is still found in "stop_pending" (this is status the job gets in after going to STOPPING status) status, I am using taskkill command to kill the service. Does this look ok? @echo off REM service_names.txt contains all service names REM This code is for starting services one after other FOR /F %%i IN (service_names.txt) DO ( sc \\servername stop %%i ping localhost -n 10 > nul sc \\servername query %%i | find /i "stop_pending" || taskkill /s computername /u userid /p password /im %%i ) TIA |
|
||
|
||||
|
Pegasus \(MVP\)
Guest
Posts: n/a
|
*** See below.
"test" <(E-Mail Removed)> wrote in message news:271710da-2e40-4b73-9e9f-(E-Mail Removed)... Thanks again Pegasus. I am now using your suggestion and not including "EnableDelayedExpansion" statement. Its working as expected. I tried the above code but got following error: C:\Documents and Settings\dir1\dir2\TempVBS.VBS(15, 2) CDO.Message.1: The "SendUsing" configuration value is invalid. I tried searching on this error but could not find on what value I should change "sendusing" value to. Can you please advise. *** Sorry, I cannot comment unless you post the version of *** the code you actually use. Also, as far as killing of services is concerned, I was able to come up with following code. Just wanted to have your suggestion this.: Each service is stopped and a delay is given after which the service's status is checked. If service is still found in "stop_pending" (this is status the job gets in after going to STOPPING status) status, I am using taskkill command to kill the service. Does this look ok? @echo off REM service_names.txt contains all service names REM This code is for starting services one after other FOR /F %%i IN (service_names.txt) DO ( sc \\servername stop %%i ping localhost -n 10 > nul sc \\servername query %%i | find /i "stop_pending" || taskkill /s computername /u userid /p password /im %%i ) *** You have the right idea but you're testing for the wrong *** thing. Since you want to check if the service has stopped, *** the code should look like so: sc \\servername query %%i | find /i "stopped" || taskkill /s computername /u userid /p password /im %%i However, there is fundamental issue here. "%%i" is the name of the SERVICE you wish to stop. Taskkill.exe will kill a TASK, not a SERVICE. What are you trying to achieve with the taskkill command? |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A script/batch to kill a batch file from scheduled tasks? | Bogdan | Windows XP Configuration | 1 | 31st Jul 2009 06:05 AM |
| Is there a way to execute a DosBox batch script on the remote computer? | mr_ravi_patil@yahoo.com | Windows XP Work Remotely | 0 | 4th Feb 2007 12:44 PM |
| Is there a way to execute a DosBox batch script on the remote computer? | mr_ravi_patil@yahoo.com | Windows XP Work Remotely | 0 | 4th Feb 2007 12:02 PM |
| Chat with ASP.NET. Web Services or Remote Script? | Dexter | Microsoft ASP .NET | 3 | 16th Jan 2005 01:16 PM |
| Batch script to start services with timer | donald beck | Microsoft Windows 2000 CMD Promt | 1 | 25th Sep 2003 07:13 PM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




