Question

Here's my issue: I created this .bat script to ping a list of hostnames in our environment. The names all have a similar naming convention, so it is set up as type.site.countrycode(cc). The types are all uniform - tc1, tc2, tc3, etc... The site and country code is entered as variables. Right now, you type in the site and cc, and it returns a list of the types and displays if they are pingable or not. Recently, I've ran into issues with DNS, and can't ping by FQDN, but can ping with IP. So instead of returning the IP's for each, and THEN pinging, I want to be able to ping, then run an nslookup on everything that is set as down. I've tried everything from setting the "down" boxes as a variable and run the nslookup against the variable, I've tried a nested loop to do it, as well as a findstr to find the "down" boxes and set those as a variable, and so many other options that I'm running out of ideas. I'm going to post the WORKING code of just pinging the boxes, and hope any methods that you suggest can point me in the right direction. Thanks in advance!!!

SET "site=%1"
SET "cc=%2"

if "%site%" equ "" (
   set /P "site=Site Number: "
   set /P "cc=Country Code (US if left blank): "
)
if "%cc%"=="" set "cc=us"
IF ERRORLEVEL 1 GOTO top
:startloop
set #=%site%
:subloop
set site=s0%site%
:reping
cls
echo Checking %site%.%cc%
echo.

for %%i in (tc1 tc2 tc3) do (
ping -n 1 -w 2000 %%i.%site%.%cc% >nul && (echo %%i is up) || (echo %%i is down)

)

No correct solution

OTHER TIPS

Perhaps something like...

    for %%i in (tc1 tc2 tc3) do (
    ping -n 1 -w 2000 %%i.%site%.%cc% >nul && (echo %%i is up) || (nslookup %%i.%site%.%cc%)

    )

?

You could also pass the nslookup command to another batch file and run it afterwards... ping -n 1 -w 2000 %%i.%site%.%cc% >nul && (echo %%i is up) || (nslookup %%i.%site%.%cc% >> nsbat.bat)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top