尝试使用LetsEncrypt创建用于自动SSL更新的脚本。
每日脚本首先检查SSL到期时间:
response="$(openssl x509 -enddate -noout -in ~/letsencrypt/www.mydomain.com/cert.pem)"
$response
是 notAfter=May 9 19:27:44 2018 GMT
我希望将其与今天的日期进行比较,并检查时差是否小于或等于7天。伪代码:
if [$response is less than 7 days away from today] then cd ~/letsencrypt $$ ~/dehydrated/dehydrated --cron --domain www.mydomain.com --out . --challenge http-01
我该怎么做呢?
我试图通过转换$response
为更可行的格式,date -d
但出现了date: extra operand ‘19:27:44’
错误。
我将解决您的实际问题,而不是您提出的具体问题:dehydrated --cron
已经为您检查日期了。
说明文件:
--cron
(-c
)签署/续签不存在/已更改/即将过期的证书。
代码:
# Check expire date of existing certificate
if [[ -e "${cert}" ]]; then
echo " + Checking expire date of existing cert..."
valid="$("${OPENSSL}" x509 -enddate -noout -in "${cert}" | cut -d= -f2- )"
printf " + Valid till %s " "${valid}"
if "${OPENSSL}" x509 -checkend $((RENEW_DAYS * 86400)) -noout -in "${cert}"; then
printf "(Longer than %d days). " "${RENEW_DAYS}"
if [[ "${force_renew}" = "yes" ]]; then
echo "Ignoring because renew was forced!"
else
# Certificate-Names unchanged and cert is still valid
echo "Skipping renew!"
(https://github.com/lukas2511/dehydrated/blob/master/dehydrated#L1234-L1253)
RENEW_DAYS
默认显示为30,但是您可以使用配置文件覆盖它;引用文档:
脱水是在几个不同的地方寻找配置文件,它将使用可以按以下顺序找到的第一个文件:
/etc/dehydrated/config
/usr/local/etc/dehydrated/config
- 您外壳程序的当前工作目录
- 运行脱水的目录
那里的示例配置文件包含以下行:
# Minimum days before expiration to automatically renew certificate (default: 30)
#RENEW_DAYS="30"
例如,要将值从默认的30天降低到7天,您可以将第二行编辑为:
RENEW_DAYS="7"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句