Want to automate some DNS checks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to automate some DNS checks
# 1  
Old 05-11-2016
Want to automate some DNS checks

I'd like to automate some common DNS checks that I do regularly. I do tech support, part of my job being to walk customers through setting up various DNS records, including SPF and DKIM. Most of these customers are small to medium sized businesses. The first part of the call is always me doing some dig commands to see what the name servers are, what their current TXT records are. Then when we're done I check again this time checking their DKIM, two TXT records with two hosts.

So working manually, first I do a couple basic checks:

Code:
dig example.com NS
dig example.com TXT

Then again to check our work, I run through everything we've done.

Code:
dig example.com TXT

dig examplehost1.example.com TXT 
dig examplehost2.example.com TXT

dig examplehost3.example.com A
dig examplehost3.example.com MX
dig examplehost3.example.com TXT

I don't have any experience with Bash scripting but I think that a Bash script would be the right tool for this job. If it were just a list of commands run on the root domain, it'd be easier but there are host names and so on to insert in front of the domain.

Any ideas and code examples on how to automate this process would be greatly appreciated. By the way, my research into dig has already yielded and improvement. I added +noall +answer to a .digrc file meaning dig now only returns the answer not all the extraneous (to me) information.

Thank you.

Last edited by RudiC; 05-11-2016 at 10:44 AM.. Reason: Changed icode tags to code tags.
# 2  
Old 05-11-2016
How do you want it to work?

Imagine that your script would:
prompt for the domain
execute a couple of dig commands
perhaps (in addition to display) have the computer check the results

So... what would you write to begin this task?
# 3  
Old 05-11-2016
Thanks for the response!!
Here's what I have so far. I don't yet know the syntax so I'm just trying to write something that seems reasonable.
Code:
#!/bin/bash

echo Please, enter a domain name.
read DOMAIN

dig $DOMAIN NS
dig $DOMAIN TXT

dig k1._domainkey.$DOMAIN TXT
dig _domainkey.$DOMAIN TXT

---------- Post updated at 07:46 AM ---------- Previous update was at 07:38 AM ----------

Any suggestions on what I should do next? I realize I have to learn Bash script syntax but does the basic logic seem reasonable? I know it's a bit simplistic but I figure I should get something to work for my first script and then add features later...

---------- Post updated at 07:53 AM ---------- Previous update was at 07:46 AM ----------

Wow, actually, my script worked. I'm shocked. It's not fancy but it basically did what i wanted. I have to improve it for sure.

Last edited by RudiC; 05-11-2016 at 11:43 AM.. Reason: Changed icode to code tags.
# 4  
Old 05-11-2016
Probably next steps would be to experiment with what is returned from the dig commands.

For instance, save the return message to a variable.
Then, see if it contains or does not contain an important message.
Finally, based on the "if" statement you just did, you could display either
OK -- full return message here
*ERROR* - unknown ___ -- full return message here

Experiment a little with this.
I know when I was a Sys Admin (long ago), I had many scripts that would run and alert me when an error. In my case, the script would email me when something was wrong.
# 5  
Old 05-11-2016
Quote:
Originally Posted by joeyg
Probably next steps would be to experiment with what is returned from the dig commands.

For instance, save the return message to a variable.
Then, see if it contains or does not contain an important message.
Finally, based on the "if" statement you just did, you could display either
OK -- full return message here
*ERROR* - unknown ___ -- full return message here

Experiment a little with this.
I know when I was a Sys Admin (long ago), I had many scripts that would run and alert me when an error. In my case, the script would email me when something was wrong.
I get what you're saying now. Sorry for being dense. You're saying that I'd do an "if" statement to process the output, presumably after validating it in some way. It would either succeed or fail. Then I need to have the script tell me what is broken if there's a problem.

I like the idea of it doing some sort of validation and then emailing or otherwise notifying me if there's a problem. I'm not sure what a problem would be I guess an invalid spf record but I'm not yet sure how to check for that.

Last edited by pica; 05-11-2016 at 12:46 PM..
# 6  
Old 05-11-2016
Your current example is rather simple where you are looking for the result.
I remember looking at sites and also doing repeated PING tests to the site to measure responsiveness. And rather than seeing results from ten PING's, I had a summary message to tell me - for instance "8/10 PING command response <__seconds"
Or, maybe you would do a WHOIS command to the domain, and grep for "STATUS" to make sure the domain is active.
# 7  
Old 05-11-2016
Great ideas. I'll make this script less simplistic and post it again. Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

DNS client added to DNS server but not working

Hi, We have built a new server (RHEL VM)and added that IP/hostname into dns zone configs file on DNS server (Solaris 10). Reloaded the configuration using and added nameserver into resolv.conf on client. But when I am trying nslookup, its not getting resolved. The nameserver is not able to... (8 Replies)
Discussion started by: snchaudhari2
8 Replies

2. Shell Programming and Scripting

Script to do the following checks

Hi , I need a script for processing below scenario. I have to check daily by doing ftp IP to check it is logging or not. So i want this activity to be automated such that if login succesful i will get "FTP LOGIN SUCCESS" in a log file and if fails i want the error message in the same log... (1 Reply)
Discussion started by: sv0081493
1 Replies

3. Shell Programming and Scripting

Daily Checks

Hey Guys, I'm seeking some assistance in getting this script to run as a cron job for the user oracle.. the script is basically to perform 2 ADRCI checks... see the script below... i'm getting the following error: /export/home/oracle/Daily_Checks/ADRCI_Daily_Checks.sh: syntax error at line 16:... (7 Replies)
Discussion started by: Racegod
7 Replies

4. Red Hat

DHCP & DNS - Clients get IP but don't register in DNS

I am trying to setup a CentOS 6.2 server that will be doing 3 things DHCP, DNS & Samba for a very small office (2 users). The idea being this will replace a very old Win2k server. The users are all windows based clients so only the server will be Linux based. I've installed CentOS 6.2 with... (4 Replies)
Discussion started by: FireBIade
4 Replies

5. Red Hat

DNS A-Record point to another DNS

Hi, I have a question on how to point the DNS server-1's A-record to second DNS server, which is DNS server-2. So, the computer can access other domain which only listed in the DNS server-2. The scenario is as follow: http://img689.imageshack.us/img689/6333/12234.png How to configure this... (4 Replies)
Discussion started by: Paris Heng
4 Replies

6. UNIX for Advanced & Expert Users

DNS server choice: Windows DNS vs Linux BIND

I'd like to get some opnions on choosing DNS server: Windows DNS vs Linux BIND comparrsion: 1) managment, easy of use 2) Security 3) features 4) peformance 5) ?? I personally prefer Windows DNS server for management, it supports GUI and command line. But I am not sure about security... (2 Replies)
Discussion started by: honglus
2 Replies

7. AIX

Pre-checks

AIX Guys!!! What pre-checks would you do on a 5.3 server before TL/SP/APAR installation? Bala (2 Replies)
Discussion started by: balaji_prk
2 Replies

8. UNIX for Advanced & Expert Users

Doing Checks on a file

I have a process that I am trying to provide a solution for and have hit a brick wall and would like some pointers in the right direction. Basically on a daily basis a report is automatically generated in a CSV format (FIRST.CSV) which includes codes and amounts in the following format: ... (6 Replies)
Discussion started by: SAMZ
6 Replies

9. UNIX for Dummies Questions & Answers

health checks

Hello Anyone please help me with a health check script on HP-UX. (1 Reply)
Discussion started by: mahlathini
1 Replies

10. Solaris

Solaris DNS Client For Microsoft DNS Server

hey guys, how to add soalris box as a microsoft DNS Client ? and how to register in the microsoft DNS ?? i managed to query from the DNS server after adding /etc/resolve.conf and editing /etc/nsswitch.conf but i need to register the soalris server (dns Client) into Microsoft DNS automatically.... (3 Replies)
Discussion started by: mduweik
3 Replies
Login or Register to Ask a Question