我想要映射东西

时间:2017-01-19 22:40:23

标签: cmd

AppServerNameList=(........)

DataServerNameList=(..........)

我有这个列表并且它被映射为一对一。我需要编写命令以便将特定数据服务器映射到app服务器。我将在我的文件中获取dataserver并通过我将调用此bat文件,并将需要获取特定的appserver。任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:0)

更改括号以包含双引号

@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
::  Search may be from Argument %1
Set Search=ottvmdx459
set  "UFTAppServerNameList=ottvmdx355 ottvmdx389 ottvmdx452 ottvmdx406 ottvmdx461 ottvmdx489 ottvmdx502 ottvmdx520 ottvmdx526 ottvmdx588 ottvmdx533 ottvmdx537 ottvmdx566 ottvmdx569 ottvmdx573 ottvmdx265 ottvmdx354 ottvmdx360 ottvmdx364 ottvmdx030"
set "UFTDataServerNameList=ottvmdx356 ottvmdx390 ottvmdx453 ottvmdx459 ottvmdx462 ottvmdx490 ottvmdx505 ottvmdx523 ottvmdx527 ottvmdx590 ottvmdx535 ottvmdx563 ottvmdx567 ottvmdx571 ottvmdx592 ottvmdx266 ottvmdx358 ottvmdx361 ottvmdx365 ottvmdx031"

:: Postional
Set /A Pos=0
For %%A in (%UFTAppServerNameList%)  Do Set "App[!Pos!]=%%A"&Set /A Pos+=1
Set /A Pos=0
For %%D in (%UFTDataServerNameList%) Do Call Set "%%D=%%App[!Pos!]%%"&Set /A Pos+=1
Set APP[
Set ott
If     defined %Search% Echo Matching AppServer for DataServer %Search% is !%Search%!
If not defined %Search% Echo DataServer %Search% not in List

第一个使用位置编号和内容AppServer构建伪数组App[x] 第二个创建环境变量,其名称为Dataserver,内容是相应的Appserver。

Set APP[Set ott只是为了演示具有此缩短输出的数组:

App[0]=ottvmdx355
App[1]=ottvmdx389
App[2]=ottvmdx452
App[3]=ottvmdx406
App[4]=ottvmdx461
..
App[19]=ottvmdx030

ottvmdx031=ottvmdx030
ottvmdx266=ottvmdx265
..
ottvmdx459=ottvmdx406
..
ottvmdx590=ottvmdx588
ottvmdx592=ottvmdx573
Matching AppServer for DataServer ottvmdx459 is ottvmdx406