0

I have just recently(in the past 24 hours) started learning how to create batch files that will help automate some tedious tasks.

The point of this project is to be able to check connectivity on multiple computers at a specific site without having to manually ping each computer

I am trying to figure out how to make a batch file that will do the following.

Ask the user "Which Site Are You Working On?
User enters the site id
Ask the user "Which computers do you want to ping?"
User enters the computer number(this is the tricky part)

  • the user will be entering 2 or more dns suffixes
  • how will they separate the dns suffix? with spaces or commas?(111,222 or 111 222) or will the line have to break after each dns suffix is entered. If so how will it know when the user is done?

Display the ping results for each dns name

NOTE: the entire DNS name will be something like 123tmnpc111. The tmnpc part will always be the same, only the prefix and suffix will vary

So when the pings are performed it will need to be something like

 ping %siteid%tmnpc%pcid1% -n 1 -w 2000
 ping %siteid%tmnpc%pcid2% -n 1 -w 2000
 ping %siteid%tmnpc%pcid3% -n 1 -w 2000

This is something simple i tested with when pinging just one DNS name. But I have no idea how to make this work for multiple(and variable) DNS names.

@echo off

echo Which Site Are You Working On?
echo/

set /p siteid=">> "
echo/

echo Which Computers Do You Want To Ping?
echo/

set /p pcid=">> "
echo/
cls

ping %siteid%pc%pcid% -n 1 -w 2000

pause > nul

If anyone could point me in the right direction it would be greatly appreciated. Thank you

Tim
  • 3
  • 3
  • How about taking two inputs rather than taking 1 single input separated by a space. And i the input is more than 2 you could like maybe stop when the user enters 0 or something. Good Luck. – Rishav Feb 18 '18 at 11:35
  • https://stackoverflow.com/questions/23600775/windows-batch-file-split-string-with-string-as-delimiter This will help. – Rishav Feb 18 '18 at 11:38

1 Answers1

1

Use a for loop to process a list

set /p "siteid=Which Site Are You Working On? >> "
echo Which Computers Do You Want To Ping?
set /p "pcid=Which Computers Do You Want To Ping? >> "
for %%a in (%pcid%) do (    
  ping %siteid%pc%%a -n 1 -w 2000
)
pause > nul

The computerlist can be delimited by commas or spaces (or mixed).

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • This worked perfectly! I am honestly surprised at how simple this ended up being. I had this idea of all sorts of crazy lines of code for some reason but this is great. Thank you ! – Tim Feb 18 '18 at 19:37