domain expiration check bash telegram

You need your own telegram bot (@BotFather) and channel to receive messages from your bot
Place this script to your bin directory, edit bot token and chat id and add tthe script to crontab.
Add your domain list (one per line) to ~/domains.txt.


#!/bin/bash
# Get domains from file
domains=($(cat ~/domains.txt))
for d in "${domains[@]}"
do
# Get the expiration date
expdate="$(whois $d | egrep -i 'Registry Expiry Date:|Expiration:|Domain Expiration Date:|Registrar Registration Expiration Date:|expire:|paid-till:|option expiration date:|Expires on|Expiry date:|Expiry Date:|Expiration date:|Expiration Date:|Renewal date:|paid-till:|Domain expires:|renewal date:|expires:|Expires:|Expires On:'| head -1 | sed -r 's!^[^0-9]+!!')"
# Turn it into seconds
expdate="$(date -d"$expdate" +%s)"
# Get the current date in seconds
curdate="$(date +%s)"
# Set exp variable
exp="$(((expdate-curdate)/86400))"
# Send info if expired in less 30 days
if [ "$exp" -lt "30" ]; then
token='xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxx'
chat=-100xxxxxxxxx
subj="\ud83d\udd25 $d expires in $exp days"
message=""
/usr/bin/curl --header 'Content-Type: Content-Type: application/json' --request 'POST' --data "{\"chat_id\":\"${chat}\",\"text\":\"${subj}\n${message}\"}" "https://api.telegram.org/bot${token}/sendMessage" > /dev/null 2>&1
fi
done