using multiple arguments in my script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using multiple arguments in my script
# 1  
Old 07-27-2010
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:
Code:
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...

Code:
 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

Last edited by pludi; 07-27-2010 at 06:29 AM.. Reason: code tags, please...
# 2  
Old 07-27-2010
Hi.

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

What you could do is something like:

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

Code:
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:
Code:
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


Last edited by Scott; 07-27-2010 at 07:14 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to call Oracle function with multiple arguments from shell script?

Dear All, I want to know how can i call oracle function from shell script code . My oracle function have around 5 input parameters and one return value. for name in *.csv; do echo "connecting to DB and start processing '$name' file at " echo "csv file name=$x" sqlplus -s scoot/tiger <!... (2 Replies)
Discussion started by: Balraj
2 Replies

2. Shell Programming and Scripting

Passing multiple arguments

Hi, I know with getopts you can pass arguments from the command line ./script -ab -c apple But it doesn't support 2 or more arguments for ONE option. Is there any other way to do this? Thanks (2 Replies)
Discussion started by: testa500
2 Replies

3. Shell Programming and Scripting

Passing multiple arguments to a shell script

Hi Gurus, Need some help with the shell scripting here. #!/bin/ksh ps -ef | grep -i sample.ksh | grep -v grep > abc.txt if then echo "sample.ksh is executing" else echo "sample.ksh is not executing" fi (1 Reply)
Discussion started by: jayadanabalan
1 Replies

4. Shell Programming and Scripting

How can multiple arguments be passed to shell script?

My requirement is that I want to pass similar argument to a shell script and process it in the script. Something like below: myScript.sh -c COMPONENT1 -c COMPONENT2 -a APPNote: -c option can be specified multiple times and -a is optional parameter I know this can be achieved using... (2 Replies)
Discussion started by: rajdeep_paul
2 Replies

5. Shell Programming and Scripting

Multiple runtime arguments

I am passing 3 runtime arguments to a shell script $path crtl1 crtl2 the crtl files contains data(filename|date|count) filename.txt|02/05/2010|10 The path contains the original data file,the code should fetch (filename|date|count) from original data file and it should match... (7 Replies)
Discussion started by: Prashanth B
7 Replies

6. Shell Programming and Scripting

Multiple arguments to read

I am developing a script where 3 other scripts are included. This is a graph related script. COMPLETE IDEA: -There are 3 different graph scripts. I would like to create a master graph with all 3 in one. -User chooses the type of graph -User is asked to enter the required auguments (... (7 Replies)
Discussion started by: newkid.7955
7 Replies

7. UNIX for Dummies Questions & Answers

redirecting arguments in a script to multiple lines in a .txt file

Ok hope my vocab is right here, i'm trying to write multiple sets of arguments to another file for example: I have a script that accepts four arguments and sends them to a another file $write.sh it then out in so the file receiver.txt would contain this: it then out in what... (2 Replies)
Discussion started by: austing5
2 Replies

8. Shell Programming and Scripting

using switch on multiple arguments

I have a switch statement, and I want to have two options performing the same thing. For example, if $opt matches "-fb" or "--fbase", I want to perform the same operation. How can I include various matches in "case" ? switch ($opt) case "-T": set Atpath = $par set opt_tpath =... (8 Replies)
Discussion started by: kristinu
8 Replies

9. Shell Programming and Scripting

Help required in passing multiple arguments from a shell script to a pl/sql block

Hi, hope everyone are fine. Please find my issue below, and I request your help in the same In a configuration file, i have a variable defined as below TEST = 'One','Two','Three' I am trying to pass this variable in to a sql script which is define in a pl/sql block as follows, In the... (1 Reply)
Discussion started by: ramakanth_burra
1 Replies

10. Shell Programming and Scripting

Run perl script with multiple file arguments

Hello everyone, I have two types of files in a directory: *.txt *.info I have a perl script that uses these two files as arguments, and produces a result file: perl myScript.pl abc.txt abc.xml How can I run this script (in a "for" loop , looping through both types of files)... (4 Replies)
Discussion started by: ad23
4 Replies
Login or Register to Ask a Question