#! /bin/bash
current_datetime=$(date +"%Y-%m-%d %H:%M:%S")
log_file="/root/crontabsh/crontabsh.log"
script_name=$(basename "$0")
# 写入开始执行脚本时间到日志文件
echo "$current_datetime : 开始执行脚本 $script_name" >> $log_file
# 停止Nginx服务
nginx -s stop
# 使用 certbot 进行证书续订 dry-run
certbot renew --dry-run >> $log_file 2>&1
# 重新启动 Nginx 服务
nginx
current_datetime=$(date +"%Y-%m-%d %H:%M:%S")
# 写入执行脚本结束时间到日志文件
echo "$current_datetime : 执行脚本结束 $script_name" >> $log_file
