1
#!/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?

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
ashaneen
  • 137
  • 1
  • 15
  • 1
    Add "set -x" to your script, and you can see the commands bash is running. – Bret Weinraub Apr 20 '18 at 08:17
  • Note that, except if you are really only targeting a single whois server for ever, parsing whois servers in a generic fashion is not for the faint of heart for various reasons. If that is a need I recommend you to use some existing libraries that do that for you. – Patrick Mevzek Apr 20 '18 at 15:36

1 Answers1

4

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.

Nic3500
  • 8,144
  • 10
  • 29
  • 40