【发布时间】:2020-08-23 19:27:40
【问题描述】:
我有这部分代码:
# Check how the kstart servers accessible
ping -n 1 sg-start-6001
$sgkstartcheck = $?
If($sgkstartcheck -ne 'True'){
$sgkstart = "10.104.170.250"
}
else {
$sgkstart = "sg-start-6001"
}
ping -n 1 am-start-4001.
$amkstartcheck = $?
If($amkstartcheck -ne 'True'){
$amkstart = "10.201.180.250"
}
else {
$amkstart = "am-start-4001"
}
ping -n 1 sh-start-8001
$shkstartcheck = $?
If($shkstartcheck -ne 'True'){
$shkstart = "10.113.170.250"
}
else {
$shkstart = "sh-start-8001"
}
ping -n 1 as-start-3001
$askstartcheck = $?
If($askstartcheck -ne 'True'){
$askstart = "10.46.160.250"
}
else {
$askstart = "as-start-3001"
}
ping -n 1 bk-start-1001
$bkkstartcheck = $?
If($bkkstartcheck -ne 'True'){
$bkkstart = "10.120.195.251"
}
else {
$bkkstart = "bk-start-1001"
}
$installfile = "windows/winlogbeat-6.2.4-windows-x86_64.zip"
$filebeatforwininstallfile = "windows/filebeat-6.2.4-windows-x86_64.zip"
$filename = "C:\winlogbeat-6.2.4-windows-x86_64.zip"
$filebeatfilename = "C:\filebeat-6.2.4-windows-x86_64.zip"
$webClient = New-Object System.Net.WebClient
$webClient.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()
if($site -eq 'HKG1') {$webClient.DownloadFile("http://hk-rep-2001/$installfile",$filename)}
elseif($site -eq 'AMS4') {$webClient.DownloadFile("http://$amkstart/$installfile",$filename)}
elseif($site -eq 'SIN1' -or 'SIN3') {$webClient.DownloadFile("http://$sgkstart/$installfile",$filename)}
elseif($site -eq 'SHA1' -or 'SHA2') {$webClient.DownloadFile("http://$shkstart/$installfile",$filename)}
elseif($site -eq 'ASH1') {$webClient.DownloadFile("http://$askstart/$installfile",$filename)}
elseif($site -eq 'BKK1') {$webClient.DownloadFile("http://$bkkstart/$installfile",$filename)}
网站是 ASH1。
为什么脚本会尝试使用 SIN 值进行下载?
站点是ASH1,为什么会进入SIN elseif?
似乎是因为在 ping 测试中,sin 是第一个,这是真的,但它使用这个脚本安装了几个 10000 个虚拟机,然后它就来了:/
【问题讨论】:
标签: powershell if-statement scripting conditional-statements