Monitor domain availability and send emails automatically

Source: Internet
Author: User

Looking at the last domain name, it happens to be in the pendingdelete state, that is, the domain name is not in use, but has not been released yet-it is estimated that this domain name is quite popular and may be stolen once it is found, so I want to write an automatic crontab to monitor its availability and send a notification automatically when it is available.

Based on the currently available commands/tools in Linux, this can be a simple shell script, however, I still use Perl, which I am familiar with, to bond these commands [1]-in my opinion, shell scripts are only used to configure the environment, such as export variables, set some alias, other logic, text operations, Perl, and so on, and use both Windows and Linux platforms.

[Use curl to retrieve webpage content]

It's too simple:

Curl www.sina.com.cn

Returns the HTML of the entire page.Code

If there is no curl, run sudo apt-Get install.

[Use iconv transcoding]

Charset of many Chinese Web pages is gb2312. To correctly match or display the character in the script, it must be converted to UNICODE:

Iconv-F gb2312-T utf8

[Parse the content and send it via mail]

For each line, parse the information that needs to be followed. For example, here I want to focus on the status of this domain name:

  my   @ page  = 'curl  $ targetpage  | iconv-F gb2312- T utf8 ';   chomp   @ page  ;  my   $ Domainstatus  ;  for   my   $ line  ( @ page  ) {  If  ( $ line  = ~ /Status: (\ W +)/) {  $ domainstatus =$  1  ;}} 

Then, if the status changes, send a mail Notification:

 If ( $ Domainstatus EQ "  Pendingdelete  "  ){  Print   "  The domain is still in pending state \ n  "  ;}  Else   # As soon as the status is changed away from "pendingdelete", running y us!  {  My   $ Message = "  Hi, policyan: \ n the domain: $ targetpage is ready, please register ASAP \ n  "  ;  My   $ Sendmail = " Echo '$ message' | mail-S' urgent: Please register the domain !!! 'Name \ @ domain.com  "  ;  Print   $ Sendmail  ;  Print ' $ Sendmail  ';} 

You must configure your mail transfer agent to send emails from the local machine using the MAIL command. Postfix is used here:

Sudo VI/etc/Postfix/Main. cf

Previously, my myhostname and mydestination formats were rejected by Netease mail because they did not meet the requirements (name @ machine-name:

From MAILER-DAEMON sat Dec 1 21:22:58 2012
From export yanh @ export yanh-virtualbox

Changed:

From MAILER-DAEMON sat Dec 1 23:10:20 2012
From baiyanh@baiyanh.com

You can, but there is still a problem with sending it to the QQ mailbox: the content of my email seems to be automatically sent...

The specific sending failure can be viewed as follows: (in fact, it will be better to use the mutt format)

$ Mail
Mail version 8.1.2 01/15/2001. type? For help.
"/Var/mail/Alibaba yanh": 11 messages 11 new
> N 1 MAILER-DAEMON @ Bai sat Dec 1 73/2597 undelivered mail returned to sender
N 2 MAILER-DAEMON @ Bai sat Dec 1 73/2576 undelivered mail returned to sender
N 3 MAILER-DAEMON @ Bai sat Dec 1 72/2556 undelivered mail returned to sender
N 4 MAILER-DAEMON @ Bai sat Dec 1 70/2302 undelivered mail returned to sender
N 5 MAILER-DAEMON @ Bai sat Dec 1 70/2302 undelivered mail returned to sender
N 6 MAILER-DAEMON @ Bai sat Dec 1 70/2302 undelivered mail returned to sender
N 7 MAILER-DAEMON @ Bai sat Dec 1 70/2302 undelivered mail returned to sender
N 8 MAILER-DAEMON @ Bai sat Dec 1 70/2302 undelivered mail returned to sender
N 9 MAILER-DAEMON @ Bai sat Dec 1 73/2470 undelivered mail returned to sender
N 10 MAILER-DAEMON @ Bai sat Dec 1 07 74/2492 undelivered mail returned to sender
N 11 MAILER-DAEMON @ Bai sat Dec 1 75/2605 undelivered mail returned to sender
& 1

Then enter a number to read the trusted email and you will see detailed error messages, such as 163 even if it tells you: http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html

[Set cron job monitoring every 5 minutes]

*/5 ****~ /Tools/monitor

[Question: how to deal with Ajax]

Curl can only get the web page when loading. If Ajax exists, those content cannot be obtained, such as hichina registration information:

Http://www.net.cn/domain/searchresult? Keyword = Douban & suffix =. com & domaintype = en # searchanchor

After using the information on a friend's website, you can get it directly:

Http://www.kingtoo.com/reg/whois.asp? Domain = Douban.com

 

This is a problem that needs to be solved. If the target website only discloses important information in Ajax, it cannot be obtained.

[1] https://gist.github.com/4186334

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.