| 
									
										
										
										
											2023-04-22 21:16:21 +00:00
										 |  |  | #!/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" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-23 18:23:39 +00:00
										 |  |  | # Discord Webhook | 
					
						
							|  |  |  | WEBHOOK_URL="WEBHOOK_URL" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 21:16:21 +00:00
										 |  |  | # 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" | 
					
						
							| 
									
										
										
										
											2023-05-23 18:23:39 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     curl -H "Content-Type: application/json" -X POST --data "{\"content\": null, \"embeds\": [{\"title\": \"$subject\", \"description\": \"$body\", \"color\": null}], \"attachments\": []}" $WEBHOOK_URL | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 21:16:21 +00:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 |