LinuxQuestions.org
Review your favorite Linux distribution.
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 08-24-2009, 12:59 AM   #1
ndn_hp
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Pinging a list of hostnames


hi there am new to bash shell programming.. i need help with to write a program where the shell will read a file called hostfile.txt where address are contain and ping it with timeout option of 5 seconds.. i need to use a while loop and read the host file
 
Old 08-24-2009, 01:44 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Show us what you've got so far. you might want to read these:
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://rute.2038bug.com/index.html.gz
 
Old 08-24-2009, 04:44 AM   #3
manya
Member
 
Registered: Apr 2004
Posts: 194

Rep: Reputation: 15
These are the codes..and I am sure you will find out how to input the file.
# ! /bin/bash

LAST=254

echo -n "Enter first 3 Octets of the Range that you want to Scan :"
read range
for ((ip=1; ip <=LAST; ip++))
do
ping -c 1 -w 1 $range.$ip > /dev/null
if [ $? -eq "0" ];then
echo "$range.$ip is alive"
else
echo "$range.$ip is not reachable"
fi
done

OR
# !/bin/bash
echo -n "Enter first 3 Octets of the Range that you want to Scan : "
read range
#for ip in $(seq 1 254);do
for ip in {1..254};do

ping -c 1 $range.$ip > /dev/null
if [ $? -eq "0" ];then
echo "$range.$ip is alive"
else
echo "$range.$ip is not reachable"
fi
done
 
  


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
exim4 and hostnames eteck Linux - Server 0 02-19-2009 05:37 PM
hostnames thenewguy05 Linux - Networking 1 07-12-2004 05:08 PM
resolving hostnames iceman47 Linux - Networking 3 10-07-2003 09:34 AM
no hostnames in host allow/deny list error with samba colpaarm Linux - Software 1 07-18-2003 10:12 AM
Hostnames glj Linux - Networking 3 02-12-2002 10:04 AM

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

All times are GMT -5. The time now is 08:13 AM.

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