Shell script to check / monitor domain renew / expiration date

Update: Check out new improved domain-check script.

Forgetting to renew your domain name can happen to all of us. According to this post:
Reports are coming in from Germany that was down for many hours yesterday, and has now gone live again. We’re trying to confirm the reason, but it appears to be because Google forgot to renew the domain name..

I am going to share my little (read as dirty) shell script. It monitors and lists domain expiration date.

whois command line client for the whois directory service. It provides domain whois information. To find out domain information you need to type:
$ whois

Find domain expiration date

To get expiration date use grep command:
$ whois | egrep -i 'Expiration|Expires on'

 Expiration Date: 10-may-2009
NOTICE: The expiration date displayed in this record is the date the
currently set to expire. This date does not necessarily reflect the expiration
view the registrar's reported date of expiration for this registration.
      Expires on: 10-May-09

Here is my script:

# Domain name list - add your domainname here
for d in $DOM
  echo -n "$d - "
  whois $d | egrep -i 'Expiration|Expires on' | head -1
  # If you need list..
  # whois $d | egrep -i 'Expiration|Expires on' | head -1 >> /tmp/
  echo ""
# [ -f /tmp/ ] && mail -s 'Domain renew / expiration date' 

Output: - Expiration Date:28-Oct-2007 13:01:58 UTC - Expiration Date:29-Jul-2008 09:17:56 UTC -    Expiration Date: 10-may-2009 - Expiration Date:13-Aug-2007 14:58:30 UTC - Domain Expiration Date:                      Fri Jun 01 23:59:59 GMT 2007 -    Expiration Date: 11-dec-2007 - Expiration Date:26-Jun-2007 11:05:13 UTC - Domain Expiration Date:                      Tue Jun 30 23:59:59 GMT 2009 - Expiration Date:25-May-2007 11:20:40 UTC - Expiration Date:14-Sep-2007 06:47:36 UTC - Expiration Date:02-Feb-2008 05:33:08 UTC

Install a script and run on weekly / monthly basis via Linux/UNIX Cron facility.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Miguel Apr 3, 2007 @ 14:42

    really cool idea! It happened to me many times… and I am really stupid that I never thougth about this simple solution….
    Thanks 🙂

  • Joe Peled Jan 27, 2010 @ 17:16

    Here’s my twist on that script – this can be ran periodically (daily/weekly/etc) and used to notify of domains expiring – can be called by nagios, etc.

    if [ $# -ne 2 ]; then
            echo "usage: $0  "
            exit 1
    expiration_string=`whois "$domain" |  egrep -i 'Expiration|Expires on' | head -1  | awk '{print $NF}'`
    if [ $? -ne 0 ]; then
            echo "ERROR executing whois for the $domain domain - $expiration_string"
            exit 1
    expiration_epoch=`date --date="$expiration_string" '+%s'`
    rightnow_epoch=`date '+%s'`
    seconds_left=`expr $expiration_epoch - $rightnow_epoch`
    days_left=`expr $seconds_left / 86400`
    if [ $days_left -le $expiration_days ]; then
    echo "$msg - $domain expires in $days_left days"
    exit $rc
  • Ham's Nov 10, 2010 @ 0:42

    For me, this is the simplest script !

    Very good, thanks !

  • Amir Nasir Nov 3, 2011 @ 11:31

    nice idea bro, thanks for sharing this

  • AZ Apr 23, 2012 @ 22:27


    How would you set the script up so that it shows expiration date and name server next to each other?

    Thank you!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum