アマチュアスクリプトコーダーここで、私のループスクリプトを目的の方法で動作させるための助けを求めています。ループ内で変数を更新する
私はpingする9つのIPアドレスのリストを持っています。これは、以下に示すように、2文字と1桁の変数で保存されます。
私が直面している2つの問題があると私はとにかく見ることができると思います。 最初に、変数に格納されているIPを呼び出そうとすると、実際に呼び出す変数内のIPではなく、必要な変数の名前をpingしようとします。
私が知っている2番目の問題は、変数の数字を増やす方法です。 IEは "AP1"を "AP2"に増やす方法などです。
ヘルプ! :(以下
は、私の状況を示すために、私のスクリプトのカットダウン版で完全なスクリプトでは多くの多くの異なる「サイト」echo off
setlocal enabledelayedexpansion
cls
:SET_SITE_ID
echo There are 3 customers set up: [1] [2] [3]
set /p SITE="Enter Site ID: "
goto %SITE%
:VERIFY_SITE_ID
cls
echo Site ID set to: %SITE%
echo Location: %LOCATION%
echo The number of AP's is: %AP_QUANTITY%
echo The controller IP is: %CONTROLLER%
echo AP1 IP: %AP1%
if defined AP2 echo AP2 IP: %AP2%
if defined AP3 echo AP3 IP: %AP3%
if defined AP4 echo AP4 IP: %AP4%
if defined AP5 echo AP5 IP: %AP5%
if defined AP6 echo AP6 IP: %AP6%
if defined AP7 echo AP7 IP: %AP7%
if defined AP8 echo AP8 IP: %AP8%
if defined SITE_NOTES echo Site Notes: %SITE_NOTES%
choice /C 12 /N /M "Is the above info correct? [1=Proceed to Ping Test] [2=Change it]"
if %errorlevel%==1 goto PING_TEST
if %errorlevel%==2 goto SET_SITE_ID
:PING_TEST
cls
choice /C 12 /N /M "Which test script? [1=Original] [2=Stephan's script]"
if %errorlevel%==1 goto PING_TEST_ORIGINAL
if %errorlevel%==2 goto PING_TEST_STEPHAN
:PING_TEST_ORIGINAL
cls
echo Starting ping test.
echo -------------------------------------------------------------------------------
echo Testing Controller...
ping -n 2 %CONTROLLER%
echo -------------------------------------------------------------------------------
echo Testing AP1 (of %AP_QUANTITY%)...
ping -n 2 %AP1%
if not defined AP2 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP2 (of %AP_QUANTITY%)...
ping -n 2 %AP2%
if not defined AP3 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP3 (of %AP_QUANTITY%)...
ping -n 2 %AP3%
if not defined AP4 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP4 (of %AP_QUANTITY%)...
ping -n 2 %AP4%
if not defined AP5 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP5 (of %AP_QUANTITY%)...
ping -n 2 %AP5%
if not defined AP6 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP6 (of %AP_QUANTITY%)...
ping -n 2 %AP6%
if not defined AP7 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP7 (of %AP_QUANTITY%)...
ping -n 2 %AP7%
if not defined AP8 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP8 (of %AP_QUANTITY%)...
ping -n 2 %AP8%
if not defined AP9 goto END_OF_PING_TEST
echo -------------------------------------------------------------------------------
echo Testing AP9 (of %AP_QUANTITY%)...
ping -n 2 %AP9%
goto END_OF_PING_TEST
:PING_TEST_STEPHAN
set count=0
for /f "tokens=2 delims==" %%a in ('set AP') do (
set /a count+=1
echo -------------------------------------------------------------------------------
echo testing %%a, [!count! of %AP_QUANTITY%]
ping -n 2 %%a
)
goto END_OF_PING_TEST
:END_OF_PING_TEST
echo -------------------------------------------------------------------------------
choice /C YN /M "End of ping test. Repeat?"
if %errorlevel%==1 goto PING_TEST
if %errorlevel%==2 exit
:1
set LOCATION=Customer 1
set AP_QUANTITY=1
set CONTROLLER=192.168.0.253
set AP1=192.168.0.252
set SITE_NOTES=Notes go here
goto VERIFY_SITE_ID
:2
set LOCATION=Customer 2
set AP_QUANTITY=2
set CONTROLLER=192.168.0.253
set AP1=192.168.0.252
set AP2=192.168.0.111
set SITE_NOTES=Notes go here
goto VERIFY_SITE_ID
:3
set LOCATION=Customer 3
set AP_QUANTITY=9
set CONTROLLER=192.168.0.253
set AP1=192.168.0.252
set AP2=192.168.0.111
set AP3=192.168.0.8
set AP4=127.0.0.1
set AP5=127.0.0.1
set AP6=127.0.0.1
set AP7=127.0.0.1
set AP8=127.0.0.1
set AP9=127.0.0.1
set SITE_NOTES=Notes go here
goto VERIFY_SITE_ID
申し訳ありません、ああ。 Windowsのコマンドラインバッチファイル –