LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 05-22-2002, 03:07 PM   #1
ewarmour
LQ Newbie
 
Registered: May 2001
Posts: 19

Rep: Reputation: 0
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
 
Old 05-22-2002, 10:54 PM   #2
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
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.
 
Old 05-23-2002, 03:40 AM   #3
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
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
 
Old 05-23-2002, 04:00 AM   #4
Brion
Member
 
Registered: May 2002
Location: Belgium
Distribution: LinuxFromScratch
Posts: 85

Rep: Reputation: 15
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
 
Old 05-23-2002, 10:05 AM   #5
ewarmour
LQ Newbie
 
Registered: May 2001
Posts: 19

Original Poster
Rep: Reputation: 0
Right on...

Thanks for the help you guys. Good stuff. -E
 
Old 05-23-2002, 10:28 AM   #6
ewarmour
LQ Newbie
 
Registered: May 2001
Posts: 19

Original Poster
Rep: Reputation: 0
Got it going

Thanks again for the help -E
 
Old 05-24-2002, 08:01 AM   #7
vfs
Member
 
Registered: Apr 2002
Location: Brazil
Distribution: Slackware
Posts: 184

Rep: Reputation: 30
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
 
Old 05-24-2002, 12:31 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well that's why you should NEVER reply to posts that have already been identified as doubleposts.... only makes you look dumb!
 
Old 05-25-2002, 07:10 AM   #9
vfs
Member
 
Registered: Apr 2002
Location: Brazil
Distribution: Slackware
Posts: 184

Rep: Reputation: 30
I didn't see any mention about double/crossposting. If I did, I surely wouldn't answer... Maybe I'm growing blind

vfs
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash shell scripting Sco Linux - Newbie 1 11-09-2004 11:58 AM
Bash shell scripting question mehesque Programming 2 07-15-2004 10:54 AM
Help with I/O on bash shell scripting Dave6383 Programming 1 06-03-2004 05:24 PM
some bash shell scripting eltongeoff Linux - Newbie 2 10-22-2003 01:10 PM
Bash Shell Scripting Help Tangerine Programming 6 05-06-2003 02:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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