#!/bin/bash
DOM="onet.pl wp.pl"
for d in $DOM
do
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/domain.date
expdate="$(whois $d | egrep -i 'Expiration|Expires on' | head -1)"
#to seconds
expdate="$(date -d"$expdate" +%s)"
#current date
curdate="$(date +%s)"
printf "Expiration date : $expdate\n"
printf "Current date : $curdate\n"
printf "Days for expiration : %s\n" "$(((expdate-curdate)/86400))"
echo ""
done
And i get a result like this :
onet.pl - option expiration date: 2019.08.16 16:52:03
date: invalid date ‘option expiration date: 2019.08.16 16:52:03’
Expiration date :
Current date : 1524210803
Days for expiration : -17641
wp.pl - option expiration date: 2020.02.10 10:51:12
date: invalid date ‘option expiration date: 2020.02.10 10:51:12’
Expiration date :
Current date : 1524210803
Days for expiration : -17641
It looks like there is something wrong with date format, i was that maybe because of text+date instead of pure date. Because of that I believe the rest is not working properly. Any ideas how to make expiration date valid?
Got it! Remove the .
(dots) in your expiration date. So do this:
#!/bin/bash
expiration_date="2019.08.16 16:52:03"
date -d"$(echo $expiration_date | tr -d '.')" +%s
The result command is thus:
date -d"20190816 16:52:03" +%s
and that is valid and proprely used by date -d.
This worked for me using date (GNU coreutils) 8.25, on Linux Mint 18 and date (GNU coreutils) 8.4 on RHEL7.