Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of xDUCKx
xDUCKx

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of omarfarid
for unix / linux try

for server in `cat servers.txt`
do
   echo ---------- $server --------->> mylog
   ping -c 4 $server >> mylog 2>&1
done
Avatar of YZlat

ASKER

what about Windows?
please see ID: 38282186 above
Avatar of YZlat

ASKER

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
Avatar of YZlat

ASKER

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.