-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathle_auto_renew.sh
36 lines (29 loc) · 1.3 KB
/
le_auto_renew.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Script to auto renew Lets Encrypt SSL certs based
# on defined # of valid days remaining.
#
# Valid for Apache installs, can be easily updated to support others.
#
# Written by agentpoyo 2019-12-27
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. <http://www.gnu.org/licenses/>.
#
# Usage: ./le_auto_renew.sh <number>
# Example: ./le_auto_renew.sh 7 # Will renew the certificates if VALID days left is less than 7 days.
# Let's extract the valid # of days left:
DAYS=`certbot certificates | grep "Expiry Date" | cut -d"(" -f2 | cut -d" " -f2`
NUM="$1"
if [ "$DAYS" -lt "$NUM" ]; then
echo "$DAYS is less than $NUM, time to renew!"
/usr/bin/certbot renew --quiet
/usr/sbin/apachectl graceful # never hurts to do a graceful restart of apache
else
echo "$DAYS valid days is greater than $NUM day(s) configured, no need to renew yet."
fi