Shell script to check domain expiry date and send alerts to Slack on Ubuntu

 

1. Create a file with list of domain names

vi /home/ubuntu/domain_names.txt
example.com
example.in
example.org
exp123.com

2. Create a shell script for domain expiry check

vi /home/ubuntu/domain-expiry-check.sh
#!/bin/bash

#Specify all the domains you want to check
WEBSITE_LIST=`cat /home/ubuntu/domain_names.txt` #WEBSITE_LIST
MAX_DAYS=30
MIN_DAYS=1
current_epoch=$(date '+%s')
for dm in $WEBSITE_LIST
do
expiry_date=$(curl -s https://www.whatsmydns.net/api/domain?q=$dm | jq --raw-output '.[].expires | select( . != null )' )
echo -n " $dm - Expires on $expiry_date "
expiry_epoch=$(date --date="$expiry_date" '+%s')
epoch_diff=$((expiry_epoch - current_epoch))
days=$((epoch_diff / 86400))
if [[ $days -lt $MAX_DAYS && $days -gt $MIN_DAYS ]];
then
echo -n " $dm - Expires on $expiry_date and $days days remaining. "
curl -X POST -H 'Content-type: application/json' --data '{"text":" *:globe_with_meridians: '$dm' - Expires on '$expiry_date' | '$days' days remaining.*"}' https://hooks.slack.com/services/TBTD5BKT3/BLZPAXXXX/XXXXXXXXXXXXXXXX
fi
done


3. Replace the slack webhook URL with your webhook URL and execute

chmod +x /home/ubuntu/domain-expiry-check.sh

./domain-expiry-check.sh


https://medium.com/@arungowda325/shell-script-to-check-domain-expiry-date-and-send-alerts-to-slack-on-ubuntu-8f573d500a80


Comments

Popular Posts

This is a SAMPLE TESTING MESSAGE sent through Cell Broadcasting System by Department of Telecommunication

Google doodle celebrates Colombia Independence Day 2023

Here's a comparison of PHP and Python syntax in a table format