0

とにかく私はこれを行うことができますか?

@echo off
REM #Testing FIND in IPCONFIG

setlocal EnableDelayedExpansion

for /f "tokens=3" %%a in ('ping localhost ^| findstr /i "reply"') do (
  set address=%%a
  set address=!address::=!
)

ipconfig /all | findstr %address%
if ERRORLEVEL = 1 goto VIP_NOT_FOUND

REM #We are here becuase the find returned a result.
REM #It is safe to execute the rest of the application.
REM #EXECUTES THE SCRIPT HERE

echo "testing works" >> testing.txt

:VIP_NOT_FOUND
REM #This part of the script is where you would handle any
REM #error logging or other admin related
echo "Could not find a VIP. - Exiting"
echo "end of script reached."

このスクリプトを Windows サーバー 2k8 ENG バージョンで実行しています。それは私に findstr : bad command line を与え続けているようです。しかし、問題がどこにあるのかわかりません。

4

1 に答える 1

2

このようなものが動作するはずです:

@echo off

setlocal EnableDelayedExpansion

for /f "tokens=3" %%a in ('ping myhost.com ^| find /i "reply"') do (
  set address=%%a
  set address=!address:~0,-1!
)

ipconfig /all | findstr "%address%" >nul && (
  rem Do stuff
)

ホストに IPv4 アドレスと IPv6 アドレスがあり、IPv4 アドレスを探している場合はping -4、単にping.

于 2013-06-14T07:54:19.540 に答える