multiple nslookups


 
Thread Tools Search this Thread
Operating Systems Solaris multiple nslookups
# 1  
Old 09-06-2010
multiple nslookups

Hi Guys

i am creating a script in tcsh to perform a nslookup to a ip address. now i need to modify the script to perform nslookups on multiple ip addresses. the ip addresses are added as variables to the script on the command line.
i also need to do a nslookup on a specific dns host.
can anyone help me?

here is the current script i have

Code:
 
 while (9)
#set n=>1
if ($# != 1) then
    echo broken
  exit
endif

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

Kind regards.
Brian

Last edited by vbe; 09-06-2010 at 09:44 AM..
# 2  
Old 09-06-2010
Please post what Operating System you have and what Shell (looks like some sort of "csh" ?).

In unix "ping servername 2" is a syntax error. Is that syntax valid on your system? What does the parameter "2" mean?

In unix "ping" does not answer "alive", and "nslookup" does not answer "find".
Please post sample successful and unsuccessful "ping" and "nslookup" commands and output from your system.
# 3  
Old 09-06-2010
Hi Methyl.

this is Solaris 10 and i am using tcsh, which is csh in essence.

the "2" is how many seconds to wait before moving on, so if the server doesnt respond in 2 seconds, the script fails. this is incase there is more than one ip address in question.

ping replies :
host is alive.
that is why i grep for alive, because that is unique to the return code we get from ping.
and the same works for nslookup. find is one of the only words to return that is unique to the success of the nslookup, and doesnt appear in the failure.
# 4  
Old 09-06-2010
n/m.

My suggestion sucks. Sorry. Smilie
# 5  
Old 09-06-2010
Suggest this post gets moved to the Solaris board. Also it is very unusual to write systems administration scripts in tcsh.

To use a non-default nameserver:
Code:
nslookup ipaddress nameserver

This User Gave Thanks to methyl For This Post:
# 6  
Old 09-06-2010
Code:
#!/bin/tcsh
if ($# < 1) then
   echo paramter broken
   exit
endif
set b = ($*)
 
foreach i ( $b )
  echo $i host informations
  echo "*******************"
   if ( " `/usr/sbin/ping $i 5 | grep alive`" == "" ) then
      echo ping broken
      echo ""
   endif
   if ( "`nslookup $i | grep find`" == "" ) then
      echo $i host records
      echo "*************"
      nslookup $i
   else
      echo $i host does not match any records
      echo "********************************"
      echo ""
      shift
   endif
end

These 2 Users Gave Thanks to ygemici For This Post:
# 7  
Old 09-06-2010
Code:
#!/bin/ksh
for i
do
	ping $i 2 >/dev/null && dig +short -x $i >/dev/null && echo $i
done

These 2 Users Gave Thanks to jlliagre For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

3. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

4. Shell Programming and Scripting

Checking File record equal to multiple of 70 or nearest number to multiple of 70

Hello, I have a file with below content - Example 3 6 69 139 210 345 395 418 490 492 I would like the result as - Multiple of 70 or nearest number in the file less than the multiple of 70 69 139 (5 Replies)
Discussion started by: Mannu2525
5 Replies

5. Shell Programming and Scripting

Assigning multiple column's value from Oracle query to multiple variables in UNIX

Hi All, I need to read values of 10 columns from oracle query and assign the same to 10 unix variables. The query will return only one record(row). I tried to append all these columns using a delimiter(;) in the select query and assign the same to a single variable(V) in unix. I thought I... (3 Replies)
Discussion started by: hkrishnan91
3 Replies

6. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

7. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

8. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

9. Shell Programming and Scripting

Need a condition to account for failed nslookups

I need some help creating a condition for looking up hosts. I have this master host file that has data in the following columns: FQDN primary IP secondary IP third IP I need the hostnames to feed into another script I use for provisioning users. The FQDN doesn't always work for... (2 Replies)
Discussion started by: MaindotC
2 Replies

10. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies
Login or Register to Ask a Question