LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-12-2020, 03:01 AM   #1
james000
Member
 
Registered: Sep 2018
Posts: 150

Rep: Reputation: 2
Script to send email, if DNS resolution fails


Hi,

Few days ago, DNS forwarding was broken between two datacenters and one of the URL was broken. At that time, when I did "nslookup gemprov.clc.prdv51.com", it failed. Below is description, how it works.

The webserver/application server of this website is on servers hosted in Raleigh/Dallas. Any query goes to this URL, reached to DNS servers of Raleigh/Dallas. prdv512.com zone is not available on Raleigh/Dallas DNS servers, so there is a forwarder set, which send this query to Seattle/Phoenix (4 in numbers) DNS servers and then it will be resolved.

As a custom solution of monitoring, I want to setup something like, we should get email if the resolution doesn't work and fails. One way I can think is, setup a cronjob like below. Can it work?
Code:
dig gemprov.clc.prdv51.com | grep NOERROR 1>/dev/null || echo "DNS lookup fail from clc" | mail -s "DNS lookup of gemprov.clc.prdv51.com fails" abc_group@prdv51.com
For testing, if I make typo in domain, then only it works.
Code:
[root@lin-32serv ~]# dig gemprov123.clc.prdv51.com | grep NOERROR
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57436
[root@lin-32serv ~]# dig gemprov.clc.comtech911.com | grep NOERROR
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56694
[root@lin-32serv ~]# dig gemprov.clc.prdv51123.com | grep NOERROR
[root@lin-32serv ~]#
What would be best way to achieve it?

Advice, please

Thanks
 
Old 09-12-2020, 04:10 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by james000 View Post
As a custom solution of monitoring, I want to setup something like, we should get email if the resolution doesn't work and fails. One way I can think is, setup a cronjob like below. Can it work?
Code:
dig gemprov.clc.prdv51.com | grep NOERROR 1>/dev/null || echo "DNS lookup fail from clc" | mail -s "DNS lookup of gemprov.clc.prdv51.com fails" abc_group@prdv51.com
Looks good to me, though grep has the -q (quiet) option, which makes the output redirection unnecessary.
Likewise, instead of the echo, you could use <<<"DNS lookup fail from clc".
Code:
dig gemprov.clc.prdv51.com | grep -q NOERROR || mail -s "DNS lookup of gemprov.clc.prdv51.com fails" abc_group@prdv51.com <<<"DNS lookup fail from clc"
EDIT: I believe that bash is required for "<<<".

Last edited by berndbausch; 09-12-2020 at 04:14 AM.
 
1 members found this post helpful.
Old 09-12-2020, 04:14 PM   #3
james000
Member
 
Registered: Sep 2018
Posts: 150

Original Poster
Rep: Reputation: 2
This helped... thanks
 
  


Reply

Tags
dns, linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl email::send.. how to send the email? hawk__0 Programming 6 12-24-2009 01:53 PM
Local network DNS resolution fails, but DNS resolution to internet is OK farge Linux - Networking 6 05-28-2008 11:49 PM
how to send email when script fails to run bryanedwards05 Linux - Newbie 5 04-24-2008 12:02 PM
Postfix : mail cannot send to send outside ( can send/receive locally) bobbinsupport Linux - Networking 3 12-15-2007 10:40 PM
Win2k3 DNS + PFsense DNS Forwarder = No internal DNS resolution Panopticon Linux - Networking 1 11-19-2007 09:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration