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
WEBSITE_LIST=`cat /home/ubuntu/domain_names.txt`
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
Post a Comment