Added files
This commit is contained in:
parent
03c5509913
commit
442af2b02d
48
check.sh
Normal file
48
check.sh
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Read the list of domains from a file
|
||||||
|
domains=$(cat /LOCATION/OF/domains.txt)
|
||||||
|
|
||||||
|
# Email settings
|
||||||
|
sender_email="SENDER_NAME"
|
||||||
|
receiver_email="RECEIVER_EMAIL"
|
||||||
|
|
||||||
|
# Initialize an empty array to store the expiring domains and their days left
|
||||||
|
expiring_domains=()
|
||||||
|
|
||||||
|
# Set number of days to search within
|
||||||
|
days_within=30
|
||||||
|
|
||||||
|
# Set time and date of search
|
||||||
|
current_datetime=$(date +%Y-%m-%d_%H:%M:%S)
|
||||||
|
|
||||||
|
# Iterate over the list of domains
|
||||||
|
for domain in $domains; do
|
||||||
|
# WHOIS query to get the expiration date
|
||||||
|
expiration_date=$(whois $domain | grep -Ei 'Expiration Date|Expiry Date|Registry Expiry Date' | awk -F ':' '{print $2}')
|
||||||
|
|
||||||
|
# Calculate the number of days left until the domain expires
|
||||||
|
if [ ! -z "$expiration_date" ]; then
|
||||||
|
expiration_timestamp=$(date -d "$expiration_date" +%s 2>/dev/null)
|
||||||
|
if [ ! -z "$expiration_timestamp" ]; then
|
||||||
|
days_left=$((($expiration_timestamp - $(date +%s)) / 86400))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the domain is expiring within set days time
|
||||||
|
if [ ! -z "$days_left" ] && [ "$days_left" -lt $days_within ]; then
|
||||||
|
# Add the expiring domain and its days left to the array
|
||||||
|
expiring_domains+=("$domain: $days_left days left")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Send an email with the expiring domains and their days left (if any)
|
||||||
|
if [ ${#expiring_domains[@]} -gt 0 ]; then
|
||||||
|
# Email content
|
||||||
|
subject="Domain Expiration Alert - $current_datetime"
|
||||||
|
body="The following domains are expiring within $days_within days:\n\n${expiring_domains[@]/%/\\n}"
|
||||||
|
|
||||||
|
# Send the email
|
||||||
|
echo -e "$body" | mail -s "$subject" -a "From: $sender_email" "$receiver_email"
|
||||||
|
fi
|
||||||
|
|
||||||
2
domains.txt
Normal file
2
domains.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
example.com
|
||||||
|
example.co.uk
|
||||||
Loading…
Reference in New Issue
Block a user