在一个特定的顺序运行在不同的远程服务器上的多个批处理文件 [英] Running multiple batch files on different remote servers in a specific order
问题描述
我有需要在在位于同一网络上的6远程服务器按照以下顺序异步运行一些批处理文件,并有共同的用户名和功放的所有服务器;密码登录。我已经把 Master.bat 文件的服务器5。
I have some batch files which need to be run asynchronously in following order on 6 remote servers located on same network and all servers having common username & password to login. I have put Master.bat file on Server5.
STEP1 :Run file1.bat on 4 different servers (Server1, Server2, Server3, Server4) in parallel
STEP2 :Run file2.bat on 2 different servers (Server5, Server6) in parallel
STEP3 :Run file3.bat on Server5 (which is local server in my case as Master.bat is on Server5 only )
STEP4 :Run file4.bat on 2 same servers as in STEP2 (Server5, Server6) in parallel
STEP5 :Run file5.bat on 4 same servers as in STEP1 (Server1, Server2, Server3, Server4) in parallel
我已经计划要做到这一点,如下所示:
I have planned to do this as follows :
Serverlist1.txt:
Server1 ip
Server2 ip
Server3 ip
Server4 ip
Serverlist2.txt:
Server5 ip
Server6 ip
Master.bat:
@echo off
setlocal enabledelayedexpansion
for /F "delims= " %i in (C:\test\Serverlist1.txt) do ( psexec \\%i C:\test\file1.bat )
for /F "delims= " %i in (C:\test\Serverlist2.txt) do ( psexec \\%i C:\test\file2.bat )
call file3.bat
for /F "delims= " %i in (C:\test\Serverlist2.txt) do ( psexec \\%i C:\test\file4.bat )
for /F "delims= " %i in (C:\test\Serverlist1.txt) do ( psexec \\%i C:\test\file5.bat )
我没有带测试它却又如此不确定是否多个作为循环中的 Master.bat 文件将等待对方完成与否?我应该把这些作为循环其他批处理文件,并将其拨打他们的 Master.bat ?
这一切似乎有点冗长me.Is有没有简单的方法来做到这一点?
需要帮助!
I havn't tested it yet so not sure whether multiple FOR loops in a Master.bat file will be waiting for each other to be finished or not ?. Should I put these FOR loops in other Batch files and them CALL them in Master.bat ? This all seems bit lengthy to me.Is there any simple method to do this ? Need help !
EDIT1
file1.bat
taskkill /f /im firefox.exe
net stop W3SVC
sc config W3SVC start= demand
net start W3SVC
我要file1.bat等到成功信号received.Where我应该file1.bat文件放在 WAITFOR SUCCESS
命令?
在上面的 Master.bat 文件,我应该插入 WAITFOR / SI SUCCESS
命令将信号发送到 file1.bat ,即可开始运行?
In above Master.bat file where I should insert waitfor /SI SUCCESS
command to send a signal to file1.bat to start running ?
其实我有定义不同的信号名称为所有五个批处理文件,sothat我可以运行它们一个接一个按照上述5个步骤。
Actually I have to define different Signal Name for all the five batch files, sothat I can run them one after another as per 5 steps mentioned above.
推荐答案
一。一种选择是连续每台服务器上运行的所有commans:例如:在Server1上,S2,S3,S4,BAT2上的S5,S6等BAT1
a. One option is to run all commans on each server successively: eg: bat1 on Server1, S2, S3, S4, bat2 on S5, S6, etc
乙。如果选项。不适合你,我没有看到一个简单的解决方案:
b. If option a. does not fit to you, I don't see a simple solution:
- 创建的每个步骤ServerlistX.txt文件(所需的服务器IP)。
- 设置步骤= 0
- 拨打所有服务器的第一步。
- 显示器如果所有服务器的批次成功完成。在这里你可以设置一个特定的窗口名称和名称和窗口名称,并关闭子窗口使用
任务列表/ FI ...
命令过滤器的进程。检查之间等待的时间可以通过模拟的平指令平本地主机> NUL
。它会持续3〜秒。 - 设置步长=步+ 1
- 检查若有步骤不超过最大并退出。
- 转到第3步。
- Create a ServerlistX.txt file for each step (with necessary servers IP).
- Set Step=0
- call all servers for first step.
- Monitor if all server batches completed successfully. Here you can set a specific window name and use
tasklist /FI ...
command to filter processes by name and window name, and close child windows. Waits between check can be emulated by ping command "ping localhost>nul
". It will last ~ 3 sec. - Set Step=Step+1
- Check if Step is not exceeding max and exit if so.
- Goto step 3.
这篇关于在一个特定的顺序运行在不同的远程服务器上的多个批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!