Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-22-2002, 03:07 PM
|
#1
|
LQ Newbie
Registered: May 2001
Posts: 19
Rep:
|
BASH Shell scripting help
I want to make shell script that takes a list of host names on my network as command line arguments and displays whether the hosts are up or down, using the ping command to display the status of a host and a for loop to process all the host names. Im new to shell scripting so Im not quite sure where to start with this. Thanks for any help -E
|
|
|
05-22-2002, 10:54 PM
|
#2
|
LQ Addict
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704
Rep:
|
you can use a perl script
usage script file count
#!/usr/bin/perl
($file, $n) = @ARGV; # $n is used by ping to expire after sending
# $n packets
print "$file \n";
print "count $n \n";
open (FH, "$file") or die "Cannot open $file:$!\n";
while(<FH>){
system ("ping -c$n $_");
}
close FH;
Last edited by neo77777; 05-22-2002 at 10:57 PM.
|
|
|
05-23-2002, 03:40 AM
|
#3
|
Senior Member
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316
Rep:
|
Here is a bash script that I use which does the same.
Code:
#!/bin/sh
checkhost()
{
echo "Checking host $1..."
ping -c 2 $1 &> /dev/null
if [ $? == 0 ]
then
echo "$1 is running"
else
echo "$1 is not reachable"
fi
}
HOSTLIST="host1 host2"
for hostname in $HOSTLIST
do
checkhost $hostname
done
|
|
|
05-23-2002, 04:00 AM
|
#4
|
Member
Registered: May 2002
Location: Belgium
Distribution: LinuxFromScratch
Posts: 85
Rep:
|
http://www.tldp.org/LDP/abs/html/index.html
here u can find a book that teaches u everything u need to know about bash scripting
|
|
|
05-23-2002, 10:05 AM
|
#5
|
LQ Newbie
Registered: May 2001
Posts: 19
Original Poster
Rep:
|
Right on...
Thanks for the help you guys. Good stuff. -E
|
|
|
05-23-2002, 10:28 AM
|
#6
|
LQ Newbie
Registered: May 2001
Posts: 19
Original Poster
Rep:
|
Got it going
Thanks again for the help -E
|
|
|
05-24-2002, 08:01 AM
|
#7
|
Member
Registered: Apr 2002
Location: Brazil
Distribution: Slackware
Posts: 184
Rep:
|
I realize why should one post so much the same!
I replied a similar message some minutes ago, from the same guy.
If I knew he had this bunch of answers, I'd save my time looking other msgs...
Damn!
vfs
|
|
|
05-24-2002, 12:31 PM
|
#8
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
well that's why you should NEVER reply to posts that have already been identified as doubleposts.... only makes you look dumb!
|
|
|
05-25-2002, 07:10 AM
|
#9
|
Member
Registered: Apr 2002
Location: Brazil
Distribution: Slackware
Posts: 184
Rep:
|
I didn't see any mention about double/crossposting. If I did, I surely wouldn't answer... Maybe I'm growing blind
vfs
|
|
|
All times are GMT -5. The time now is 09:26 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|