Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (9.5k points)

Below is my code implementation:

#!/bin/bash

DOM="onet.pl wp.pl"

for d in $DOM

do

  echo -n "$d - "

  whois $d | egrep -i 'Expiration|Expires on' | head -1

   whois $d | egrep -i 'Expiration|Expires on' | head -1 >> /tmp/domain.date

  echo ""

done

#[ -f /tmp/domain.date ] && mail -s 'Domain renew / expiration date' [email protected] < /tmp/domain.date || :

This code sends automatic mail when the domain expires. I’ve managed to code to show the expiration date and to send an email with an output. Can anyone tell me how to compare the expiration date with the current data which gives the result as a number of days? 

1 Answer

0 votes
by (19.7k points)

You just need to add the date command “date -d” to parse the date:

# Get the expiration date

expdate="$(whois $d | egrep -i 'Expiration|Expires on' | head -1)"

# Turn it into seconds (easier to compute with)

expdate="$(date -d"$expdate" +%s)"

# Get the current date in seconds

curdate="$(date +%s)"

# Print the difference in daysprintf "Number of days to expiration : %s\n" "$(((expdate-curdate)/86400))"

Interested in Linux? Check out this Linux Certification by Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 14, 2021 in Linux by sheela_singh (9.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...