-4

I have a CSV file with the hostnames of 6,000+ servers. I need to ping each one.

Any idea how to create a python script like this?

Thanks!

  • 1
    Have you tried that? Where is your code? – Remi Guan Sep 22 '15 at 23:46
  • Going to be the same in any language. Read the file into a structure of some kind. Run a loop over the structure, reading one with each loop. In the loop, make a call to each server. Questions will be around whether you want to do it one a time, or send them all off in batches. But it's pretty simple stuff. – CargoMeister Sep 22 '15 at 23:52
  • #!/bin/bash while read hostname do ping -c 1 -t 1 "$hostname" > /dev/null 2>&1 && echo "Ping Status of $hostname : Success" || echo "Ping Status of $hostname : Failed" done < app.txt – Nina Paige Sep 24 '15 at 23:00

1 Answers1

0

Open file, for-loop through hosts (easiest if 1 per line), then ping.

To learn how to ping, try reading this article: Pinging servers in Python

Then, just make a small routine that opens file, loops through lines, and pings each one.

with open("file") as f: 
  for host in f:
    ping(host)  # <- not legit; replace this line; see comment below

Note: you will need to replace "ping(host)" with code that you create after being inspired by the "Pinging servers in Python" Q&A or another article... or by just flat-out copying their example.

Community
  • 1
  • 1
Dimitri
  • 1
  • 2