using multiple arguments in my script

hi all

i am creating a script to ping hosts and then do a nslookup.
So what needs to happen is that i type the script name with an argument eg:

zong (script name) 172.x.x.x (IP)

at the moment i have got it to take on argument, but idealy i would like it to take more than 1 argument. can you help? here is the script below...

 if ($# !=1) then 
   echo broken
  exit
 endif

if ("`ping $1 2 | grep alive`" !="") then
  if ("`nslookup $1 | grep find`" !="") echo "$1"
  endif
exit

this script is written in tcsh.

can anyone help please?

regards,

Brian

Hi.

I couldn't quite get your script to work. And not being a fan of the C-shell, didn't try too hard :slight_smile:

What you could do is something like:

#!/usr/bin/csh
while( "$1" != "" )
  # do what you have to do...  ping, nslookup, etc. as before
  shift
end
shift [variable ]

       The    components  of    argv, or variable, if supplied, are shifted to
       the left, discarding the first component. It is an  error  for  the
       variable not to be set or to have a null value.

Or you could use a for-loop. In a decent shell (i.e. not csh!), such would be each:

for SERVER in $@; do
  if ping $SERVER| grep alive; then
    echo "Server alive..."
    if nslookup $SERVER 2>&1 | grep  Non-existent; then
      echo "No server..."
    fi
  fi
done