Ubuntu 18.04.6 LTS on aliyun vps
# lsb_release -a
LSB Version: core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic
certbot-renew.sh
#!/bin/bash
echo "==================Certbot Renew====================="
echo "==================`date`============================"
LOG_FILE="/var/log/letsencrypt/renewal.log"
echo "$(date) - 开始证书续期" >> $LOG_FILE
sudo certbot certificates
service nginx stop
certbot renew
sudo certbot certificates
service nginx restart
echo "==================End==============================="
# certbot --version
certbot 2.8.0
A Ubuntu system has the following cron tab files and directories:
系统级别预定义用于存放定时任务脚本的目录 :
/etc/cron.hourly/:每小时执行的脚本
/etc/cron.daily/:每天执行的脚本
/etc/cron.weekly/:每周执行的脚本
/etc/cron.monthly/:每月执行的脚本
@iZnh03:/etc# ls cron*
cron.d:
cron.daily:
cron.hourly:
cron.monthly:
cron.weekly:
vi /etc/cron.d/certbot
# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew
crontab
0 3 1 * * /ktt/crons/certbot-renew.sh &>> /ktt/crons/certbot-renew.log
&>>
& 指将标准输出和标准错误输出都重定向到certbot-renew.log文件;
> 指覆盖写入到文件;
>> 指追加写入到文件。
sudo crontab -e
0 3 1 * * /ktt/crons/certbot-renew.sh &>> /ktt/crons/certbot-renew.log
0 3 1 * * 指每个月1号3点0分执行任务
cron job cerbot Let‘s Encrypt证书自动续期
Useful links
crontab的语法规则格式(每分钟、每小时、每天、每周、每月、每年定时执行 规则)