LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2018, 08:39 PM   #1
hebruiser
LQ Newbie
 
Registered: Mar 2018
Location: NC
Distribution: CentOS, Mint 18.4, Fedora 27 and Solus
Posts: 6

Rep: Reputation: Disabled
For loop iterating over a list of IP addresses from a txt file


It's me again. I have the script working, but the script is not pinging the address 3 times and moving on to the next address. Also, the message that I want to display before each new ping session is not printing.

As always, any help is great.

Here's the cute little codelette I have so far...

Code:
#!/bin/bash

# Script to test server connectivity using ping

for addr in $(cat vms.txt)
do
	echo "Pinging IP address "$addr 
	ping -c 3 "$addr"
done
 
Old 03-03-2018, 09:08 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
seems like it worked for me
what is your test file looking like?
Code:
#!/bin/bash

# Script to test server connectivity using ping

for addr in $(cat pingy)
do
    echo "Pinging IP address "$addr 
    ping -c 3 "$addr"
done
Code:
yahoo.com
google.com
www.linuxquestions.org
Code:
$ ./pingloop
Pinging IP address yahoo.com
PING yahoo.com (206.190.39.42) 56(84) bytes of data.
64 bytes from media-router-fp1.prod.media.vip.gq1.yahoo.com (206.190.39.42): icmp_seq=1 ttl=46 time=85.9 ms
64 bytes from media-router-fp1.prod.media.vip.gq1.yahoo.com (206.190.39.42): icmp_seq=2 ttl=46 time=88.4 ms
64 bytes from media-router-fp1.prod.media.vip.gq1.yahoo.com (206.190.39.42): icmp_seq=3 ttl=46 time=87.8 ms

--- yahoo.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 85.923/87.426/88.496/1.094 ms
Pinging IP address google.com
PING google.com (172.217.6.174) 56(84) bytes of data.
64 bytes from dfw25s17-in-f14.1e100.net (172.217.6.174): icmp_seq=1 ttl=53 time=23.9 ms
64 bytes from dfw25s17-in-f14.1e100.net (172.217.6.174): icmp_seq=2 ttl=53 time=25.3 ms
64 bytes from dfw25s17-in-f14.1e100.net (172.217.6.174): icmp_seq=3 ttl=53 time=27.6 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 23.951/25.640/27.601/1.502 ms
Pinging IP address www.linuxquestions.org
PING www.linuxquestions.org (75.126.162.205) 56(84) bytes of data.
64 bytes from www.linuxquestions.org (75.126.162.205): icmp_seq=1 ttl=53 time=30.5 ms
64 bytes from www.linuxquestions.org (75.126.162.205): icmp_seq=2 ttl=53 time=21.1 ms
64 bytes from www.linuxquestions.org (75.126.162.205): icmp_seq=3 ttl=53 time=30.1 ms

--- www.linuxquestions.org ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 21.113/27.277/30.548/4.365 ms
 
Old 03-03-2018, 10:23 PM   #3
hebruiser
LQ Newbie
 
Registered: Mar 2018
Location: NC
Distribution: CentOS, Mint 18.4, Fedora 27 and Solus
Posts: 6

Original Poster
Rep: Reputation: Disabled
Perfect. Thank you. It appears, since I was experimenting with Geany (I use VIM all the time), I hadn't saved the script so the changes were not registering. Thank you for everything! I am the crowned prince of making things harder than they need to be.

Last edited by hebruiser; 03-03-2018 at 10:29 PM.
 
Old 03-03-2018, 10:33 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by hebruiser View Post
Perfect. Thank you. It appears, since I was experimenting with Geany (I use VIM all the time), I hadn't saved the script so the changes were not registering. Thank you for everything! I am the crowned prince of making things harder than they need to be.
perhaps slowing down a bit and double checking your work might help.
No harm no foul.
Cheers!
 
  


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
loop iterateration problem while reading .txt file pimpant Linux - Newbie 2 11-06-2016 01:54 PM
[SOLVED] need to block list of sites from txt file iptables Net_Spy Linux - Networking 6 12-08-2015 11:06 PM
[SOLVED] Loop through list of URLs in txt file, parse out parameters, pass to wget in bash. dchol Linux - Newbie 16 07-27-2011 02:19 PM
Bash Program to monitor IP addresses in a txt file. threeonethree Programming 6 10-14-2010 11:07 AM
How can I send mails to multiple addresses in a txt file will824 Linux - Software 8 09-14-2006 10:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:04 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