terça-feira, 7 de dezembro de 2010

dnscmd - script to insert and remove DNS records from your windows 2003 DNS server


== The problem ==

I needed to insert and remove MX records from the DNS server of my job. They are about 40 subdomains that contains MX, it's not an easy task to insert and remove these records manualy. With my friend's help, we made de script listed in this post.

== The solution ==

To use the script, set the variable "BASE" with the path to the base directory where the script is; configure the variable "DOMINIO" with the name of your domain; create a file called "subdominios.txt" in the same directory where the script is. Inside this file, list all the subdomains that you like to change, don't put ".aob.com", only the name of the subdomain. The file have to be like that:

dominio1
dominio2
dominio3

To execute the script, pass the following parameters:
parameter1 = add, to add records to the subdomains listed in subdominios.txt;
delete, to delete.
parameter2 = the name of the destination server of the added MXs.
Ex.1:
script.bat add email.aob.com
This example will add MX records to all subdomains in subdominios.txt with destination to email.aob.com.

Ex.2:
script.bat delete email.aob.com
This example will delete all MX records from the subdomains in subdominios.txt with destination to email.aob.com.


== The script code is listed bellow: ==

@echo off
set BASE=C:\scripts\atualizamx\
set DOMINIO=aob.com

rem add, delete
set comando=%1

rem antispam1,antispam2,...
set servidor=%2

cd %sBase%

if "%1"=="delete" goto delete
if "%1"=="add" goto add
goto fim

:add
FOR /F %%s IN (subdominios.txt) DO (
dnscmd /recordadd %DOMINIO% %%s MX 10 %servidor%
)
goto fim


:delete
FOR /F %%s IN (subdominios.txt) DO (
dnscmd /recorddelete %DOMINIO% %%s MX 10 %servidor% /f
)

:fim

@echo on




Sorry my english, I'm learning yet!

Nenhum comentário: