LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2008, 06:32 PM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
ping from a file (not fping)


Does anyone know how to ping a bunch of IPs from a file? ping < file.txt doesn't work. I don't want to use fping, rather want to make do with GNU ping that is available on every linux distro.

Thanks for any help.
 
Old 02-04-2008, 06:46 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If file.txt contains one IP per line, a while loop can do the trick:
Code:
while read ip
do
   if ping -c 2 -w 2 -q $ip > /dev/null
   then
       echo $ip alive
   else
       echo $ip does not respond
   fi
done < file.txt
 
Old 02-04-2008, 07:45 PM   #3
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
A question, because I don't know, but couldn't the following also work? (again, if 1 IP per line)

cat file.txt | xargs ping

As I understand it, that should use each individual line of the file as an argument to separate ping commands ...

Edit: Nope, apparently it doesn't. Move along, nothing to see here

Last edited by Poetics; 02-04-2008 at 07:47 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Ping Issue - Can't ping localhost but can ping others on LAN code_slinger Linux - Networking 15 03-30-2015 02:39 PM
PPP establish can ping the gateway router but unable to ping the host deepalalla Linux - Networking 0 11-18-2004 09:10 AM
windows 98 m/c ping to ip address of red hat server but fails to ping hostname ravilohot Linux - Networking 2 09-07-2004 04:57 AM
Ping - Logging the times to a file. johnsont Programming 2 09-09-2003 01:09 PM
fping says > duplicate for [0] saavik Linux - Networking 2 09-30-2002 01:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration