?
Solved

Batch file or script to run NSLOOKUP commands

Posted on 2007-08-03
9
Medium Priority
?
18,894 Views
Last Modified: 2010-04-21
I would like to automate a series of NSLOOKUP commands. We use nslookup to generate a list of entries in our DNS

Because these commands are run from inside NSLOOKUP is there any way to make a batch file or script to run the series of commands?

Thanks,
0
Comment
Question by:bbcac
  • 5
  • 4
9 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 19625065
Sure. The most common way is to create a file with the list of servers you want to perform an action on (in this case nslookup). Then you loop through the server list and run the designated command or commands redirecting the output to a summary file.

@echo off

setlocal

if exist output.txt del output.txt

for /f "tokens=*" %%a in ('type servers.txt 2^>NUL') do nslookup "%%a" >>output.txt
0
 

Author Comment

by:bbcac
ID: 19625174
I need to run these command

>nslookup
> server DNSSERVER
> ls abc
0
 

Author Comment

by:bbcac
ID: 19625182
how can I automate internal commands like that?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 30

Expert Comment

by:SteveGTR
ID: 19625291
@echo off

setlocal

if exist output.txt del output.txt

for /f "tokens=*" %%a in ('type servers.txt 2^>NUL') do call :PROCESS "%%a"

echo Output in output.txt

goto :EOF

:PROCESS

(echo server %~1)>_temp.txt
(echo ls abc)>>_temp.txt
(exit exit)>>_temp.txt

type _temp.txt|nslookup >>output.txt 2>&1

goto :EOF
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 19625295
Forgot to clean up temporary file:

@echo off

setlocal

if exist output.txt del output.txt

for /f "tokens=*" %%a in ('type servers.txt 2^>NUL') do call :PROCESS "%%a"

echo Output in output.txt

goto :EOF

:PROCESS

(echo server %~1)>_temp.txt
(echo ls abc)>>_temp.txt
(exit exit)>>_temp.txt

type _temp.txt|nslookup >>output.txt 2>&1

del _temp.txt >NUL

goto :EOF
0
 

Author Comment

by:bbcac
ID: 19625792
that code doesn't work... it makes the _temp.txt file but it doesn't create the output.txt file

If i run the batch file and then goto the dos prompt and type in
type _temp.txt|nslookup >>output.txt
Then the output .txt file is made

Any ideas?
1
 

Author Comment

by:bbcac
ID: 19625876
just so you know, I dont' have to run this on a list of servers... it wil only every run those three commands so it doesn't really have to pull in the server name from a .txt file?
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 2000 total points
ID: 19625935
The script runs as I posted it on my machines. But, since you don't need to run it on multiple servers we can simply it:

@echo off

(echo server DNSSERVER)>_temp.txt
(echo ls abc)>>_temp.txt
(exit exit)>>_temp.txt

type _temp.txt|nslookup >output.txt 2>&1

del _temp.txt >NUL

0
 

Author Closing Comment

by:bbcac
ID: 31407583
Thanks so much, sorry it took so long to accept
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Integration Management Part 2
Loops Section Overview
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question