User Tools

Site Tools


howtos:domain_renewal_check

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

howtos:domain_renewal_check [d/m/Y H:i] (current)
Line 1: Line 1:
 +<file>
 +#!/bin/bash
 +TO="domingo@domingo.dk"
 +FROM="root@domingo.dk"
 +DBLIST=$(mysql -uroot -pPASSWORD -B -e "use postfixadmin; select domain from domain;"| egrep -v "ALL|domain")
  
 +date2stamp () {
 +    date --utc --date "$1" +%s
 +}
 +
 +stamp2date (){
 +    date --utc --date "1970-01-01 $1 sec" "+%Y-%m-%d %T"
 +}
 +
 +dateDiff (){
 +    case $1 in
 +        -s)   sec=1;      shift;;
 +        -m)   sec=60;     shift;;
 +        -h)   sec=3600;   shift;;
 +        -d)   sec=86400;  shift;;
 +        *)    sec=86400;;
 +    esac
 +    dte1=$(date2stamp $1)
 +    dte2=$(date2stamp $2)
 +    diffSec=$((dte2-dte1))
 +    if ((diffSec < 0)); then abs=-1; else abs=1; fi
 +    echo $((diffSec/sec*abs))
 +}
 +mail (){
 +local DOMAIN="$1"
 +local OWNER="$2"
 +local DAYSLEFT="$3"
 +local TO="$4"
 +local FROM="$5"
 +local NSERVER="$6"
 +
 +cp /root/domain_check/mail-template.msg /tmp/domain_check.$$
 +
 +sed -e "s/DOMAIN/$DOMAIN/g" \
 +    -e "s/OWNER/$OWNER/g" \
 +    -e "s/DAYSLEFT/$DAYSLEFT/g" \
 +    -e "s/TO/$TO/g" \
 +    -e "s/FROM/$FROM/g" \
 +    -e "s/NSERVER/$NSERVER/g"  /tmp/domain_check.$$ | sendmail -i -f $FROM -- $TO 
 +
 +}
 +
 +for i in $DBLIST
 +do
 + whois $i > /tmp/whois.$$
 + OWNER=$(cat /tmp/whois.$$ | egrep -i "owner:|^name:|^Registrant Name:" | awk '{print ($2,$3,$4)}' | sort -u | cut -d: -f2)
 + EXPIREDATE=$(cat /tmp/whois.$$ | egrep -i "^expires|^Expiration Date" | awk '{print $2'} | cut -d: -f2)
 + EXPIRES=$(date --rfc-3339=date --date $EXPIREDATE)
 + TODAY=$(date "+%Y-%m-%d")
 + DAYSLEFT=$(dateDiff -d $TODAY $EXPIRES)
 + NS=$(cat /tmp/whois.$$ | egrep -i "^nserver|^hostname|name server"| awk '{print $2}'| cut -d: -f2)
 + NSERVER=$(echo $NS| sed -e "s/ /\, /g")
 +
 +
 + echo $i is owned by $OWNER for the next $DAYSLEFT
 +
 + if [ $DAYSLEFT -lt 3000 ]
 + then
 + mail $i "$OWNER" $DAYSLEFT $TO $FROM "$NSERVER"
 + fi
 + sleep 2
 + rm /tmp/whois.$$
 +done
 +</file>
 +
 +Mail template:
 +
 +<file>
 +From: "din System Administrator" <FROM>
 +MIME-Version: 1.0
 +To: TO
 +Subject: \\\///\\\///### =?ISO-8859-1?Q?DOM=C6NE_ALARM_FOR_DOMAIN_?=
 + =?ISO-8859-1?Q?=23=23=23=5C=5C=5C///=5C=5C=5C///?=
 +Content-Type: multipart/alternative;
 + boundary="------------090809090805040807050202"
 +
 +This is a multi-part message in MIME format.
 +--------------090809090805040807050202
 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 +Content-Transfer-Encoding: 8bit
 +
 +
 +:-$ _/*Husk at forny domænet DOMAIN*/:-$ _
 +
 +Der er _/*DAYSLEFT*/_ dage tilbage
 +
 +Ejer: OWNER
 +Name Servers: NSERVER
 +
 +
 +--------------090809090805040807050202
 +Content-Type: text/html; charset=ISO-8859-1
 +Content-Transfer-Encoding: 7bit
 +
 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 +<html>
 +  <head>
 +    <meta http-equiv="content-type" content="text/html;
 +      charset=ISO-8859-1">
 +  </head>
 +  <body bgcolor="#ffffff" text="#000000">
 +    <br>
 +    <meta http-equiv="content-type" content="text/html;
 +      charset=ISO-8859-1">
 +    <div align="center"><big><big><big><small><span
 +                class="moz-smiley-s12"><span> :-$&nbsp; </span></span><u><i><b>Husk
 +                    at forny dom&aelig;net DOMAIN</b></i><span
 +                  class="moz-smiley-s12"><span> :-$ </span></span></u><br>
 +              <br>
 +            </small></big></big></big>
 +      <div align="left">Der er <u><i><b><font color="#ff0000">DAYSLEFT</font></b></i></u>
 +        dage tilbage<br>
 +        <br>
 +
 +        <br>
 +        Ejer: Thomas Dahlmann <br>
 +        Name Servers: NSERVER <br>
 +        <br>
 +      </div>
 +    </div>
 +  </body>
 +
 +</html>
 +
 +--------------090809090805040807050202--
 +</file>
howtos/domain_renewal_check.txt · Last modified: d/m/Y H:i (external edit)