batch file to ping multiple servers

I have a flat file with a list of server names and I need to create a batch file to read from the text file and ping each server. Can anyone help?
LVL 35
YZlatAsked:
Who is Participating?
 
xDUCKxConnect With a Mentor Commented:
FOR EACH %%i IN <TextFile> DO
ping %%i >> C:\Outputfile.txt

Open in new window

0
 
omarfaridCommented:
for unix / linux try

for server in `cat servers.txt`
do
   echo ---------- $server --------->> mylog
   ping -c 4 $server >> mylog 2>&1
done
0
 
YZlatAuthor Commented:
what about Windows?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
omarfaridCommented:
please see ID: 38282186 above
0
 
YZlatAuthor Commented:
I created a batch file with the following content:

FOR EACH %%i IN C:\inputfile.txt DO
ping %%i >> C:\Outputfile.txt


when I runit, it does not create C:\Outputfile.txt
0
 
YZlatAuthor Commented:
this worked for me:

FOR /F %%i IN (C:\inputfile.txt) DO ping %%i >> C:\Outputfile.txt 

Open in new window


but when I tried

FOR /F %%i IN (%1) DO ping %%i >> C:\Outputfile.txt 

Open in new window


I got the following in my Outputfile.txt:

Ping request could not find host C:\inputfile.txt. Please check the name and try again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.