Get a given date and subtract it to 5 days ago

Hi all,

I have been researching to obtain SSL certification expiry for most of our webistes. For some cases, some hosts where not directly accessible so i finally got a solution working with curl using my proxy. This lists the expiry date which i'm finally looking for.

[matt@server]# curl --proxy http://x.x.x.x:xxxx --insecure -v https://matt.com/ 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }' | grep "expire date"
*       expire date: Feb 13 23:59:59 2019 GMT

The next step is to try to find a way to get notified 5 days before that date (no emails).

First thoughts are to extract the date using awk/sed from the above result and convert it to epoch:

 date --date="13-Feb-19" +%s
1550012400

Then i was thinking to somehow subtract this date to 5 days ago and convert it to epoch time. With both values in hand i subtract and the difference will be the said threshold. if less then, it means less then 5 days prior to expiry.
However i don't see how we can get a GIVEN date and subtract.
Do you have some thoughts or maybe other ideas?

Rgds,

Matthew

You didn't mention your OS nor date versions, but your usage of date --date= leads me to infer

date --date="13-Feb-19 -5days"
Fr 8. Feb 00:00:00 CET 2019

might work on your system. Would that help?

Other idea: If you have an electronic / online calender, get the expiry date once and enter it into that calender.

today_plus_5=$(date --date="today + 5 days" +%s)
expire=$(date --date="13-Feb-19" +%s)
if [ $today_plus_5 -ge $expire ]; then echo "will expire in 5 days"; fi

Or

today=$(date +%s)
expire_minus_5=$(date --date="13-Feb-19 - 5 days" +%s)
if [ $today -ge $expire_minus_5 ]; then echo "will expire in 5 days"; fi

Gnu date will be able to parse the initial expiry date string, ie Feb 13 23:59:59 2019 GMT without the need to munge it into, eg 13-Feb-19 . All the suggestions in the above examples should work just as well with that initial string.

Andrew

Hi,

Thanks everybody for the replies. The "-5days" part is what i was missing!

Yes Andrew, you don't need to munge it at all.

Rgds