BASH shell script question

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

Well, this sounds kind of like a small assignment (homework, or real work), but I think we can get you on the right path...

Check the manual page (man bash)... Check into using a "for" loop...

for variable in "list of servers"
do
ping $variable
(do some other stuff to see if it worked)
done

If you work on the script a little, I'm sure someone could help you more if you post problem areas...

Heres what I got going so far:

 
#!/bin/bash
###############################
# 15.11
# Check host shell script
#
#
#
#
###############################

#Get our list of hosts

echo -n "Enter hosts: "
        read hosts
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="$hosts"

for hosts in $HOSTLIST
do
  checkhost $hosts
done

I got some help from another forum but I'm still not getting a result. I always get host not reachable. Im fairly certain its a problem with the hosts/hostlist vars, Im missing something somewhere. -E

Close...

Whoever did this for you, or suggested the use of function is making things more difficult that they need to be... Here's a script following similar flow that should work:

#!/bin/bash
# The \c at the end tells it not to
# return to the next line... just for looks

echo -e "What hosts shoud I check: \c"
read hosts

# What ever you type in at the end is read
# into a variable named hosts
# Now I'll use "each" in hosts, instead of 
# trying to reassign $hosts

for each in $hosts
do
# send all output away... rely on the reutrn code instead
ping -c 2 $each >/dev/null 2>&1
# if the return is Not Equal to 0 (successful)...
if [ "$?" -ne "0" ]; then
echo "Host $each is not reachable! "
fi
done

This one works for me...
Check the man page for test and for bash.
If you don't understand something in the script, please post back.