Script to help check if the domain is expiring (don’t forget change e-mail in script – now is soban@soban.pl):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ cat /root/check_domain.sh #!/bin/bash # Domain name list - add your domainname here email=soban@soban.pl DOM=`grep server_name /etc/nginx/conf.d/* | awk '{print $3}' | sed 's/\.$//'` DOMAIN=`ls /etc/nginx/conf.d/ | sed -e 's/\<conf\>//g' | sed -e 's/\<ssl\>//g' | sed 's/\.$//' | sed 's/\.$//' && echo -e $DOM | sed 's/\;/''/g'` DOM=`echo -e $DOMAIN | tr ' ' '\n' | sed 's/\;/''/g'| sort -u` for d in $DOM do date_exp=`whois $d | egrep [0-9] | egrep -i 'Expiry|renewal|Expiration' | tr '.' "-" | head -1 | sed 's/^[^:]*://g' | awk '{print $1}'` if [ ! -z "$date_exp" ]; then left=`echo $(expr '(' $(date -d $date_exp +%s) - $(date +%s) + 86399 ')' / 86400)` echo "$d - `date -d $date_exp +%F` - $left days until expiration" if (( $left < 30 )); then echo "$d - `date -d $date_exp +%F` - $left days until expiration" | mail -s "$d - DOMAIN EXPIRES!!" $email fi fi sleep 300 done |
This way you can download the script and give it permission to run:
1 2 3 |
$ cd /root/ $ wget https://soban.pl/bash/check_domain.sh $ chmod +x check_domain.sh |
And now we can add it to crontab, on monday for example:
1 2 3 |
$ crontab -e # checking domains every Monday 00 08 * * 1 date >> /root/expiring_domain && /root/check_domain.sh >> /root/expiring_domain |