V
V
Viktor Taran2019-08-30 14:07:17
bash
Viktor Taran, 2019-08-30 14:07:17

How to subtract dates with different timezones in sh?

you need to follow the date of the certificate on the site. ( openssl will not work because the certificate still needs to be validly applied and not just present)

curl -sIv https://letsencrypt.ks03.ru |& grep "expire date:" | sed -e 's/\(.*\)expire date: //g'

Conclusion:

Nov 28 09:32:50 2019 GMT

local time
date
Conclusion
Fri Aug 30 14:08:04 MSK 2019

you need to make sure that the certificate is still available, say 10 days. (we delete the time, it’s not needed only days)
then it occurred to me that 24 hours are not significant at all, so time zones are not needed at all, anyway, we follow with a margin.
So it remains only to subtract the dates

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Radjah, 2019-08-30
@shambler81

Convert the output to the desired format and compare.

$ TZ=GMT date
Пт авг 30 12:13:14 GMT 2019

$ LC_ALL=C TZ=GMT date +%Y%m%d%H%M%S
20190830121541

$ LC_ALL=C TZ=GMT date --date="Nov 28 09:32:50 2019 GMT" +%Y%m%d%H%M%S
20191128093250

Or add to cron run "certbot renew" every two months, for example.

C
chupasaurus, 2019-08-30
@chupasaurus

$EXPIRE=`curl -sIv https://letsencrypt.ks03.ru |& grep "expire date:" | sed -e 's/\(.*\)expire`
$ALERT_DATE=`date -I --date "$EXPIRE - 10 days"`
$NOW_DATE=`date -I`
expr "$ALERT_DATE" \< "$NOW_DATE" > /dev/null && notify

The magical parameters of the date utility: -Iprints the date without time in ISO format compared as a string but according to the local time zone, --dateuniversally eats various strange expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question