-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcertExpire.sh
More file actions
66 lines (54 loc) · 1.94 KB
/
certExpire.sh
File metadata and controls
66 lines (54 loc) · 1.94 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# -------------------------------------------------------------------------
# @Programa
# @name: certExpire.sh
# @versao: 0.0.2
# @Data 23 de Abril de 2025
# @versao: 0.0.1
# @Data 24 de Julho de 2019
# @Copyright: Verdanatech Soluções em TI, 2019, https://www.verdanatech.
# @Copyright: Halexsandro de Freitas Sales <halexsandro@gmail.com>
# --------------------------------------------------------------------------
# LICENSE
#
# certExpire.sh 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.
#
# certExpire.sh 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.
#
# If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------
#
# Checa a data de expiração de um certificado digital e retorna sua data em dias.
#
#
# Valores Retornados
# *Retorna um valor inteiro com a quantidade de dias faltantes para a expiração do certificado.
#
# IMPORTANTE: necessario ter o CURL instalado.
# --------------------------------------------------------------------------
if [ -z $1 ]
then
# Falta da BASEURL
echo "-1"
exit 1;
fi
host="$1"
expiration_string=$(curl -s -v --insecure "$host" 2>&1 | grep "expire date" | awk '{print $4, $5, $6, $7}')
if [ -n "$expiration_string" ]
then
expiration_date=$(date -d "$expiration_string" +%s)
current_date=$(date +%s)
seconds_to_expire=$((expiration_date - current_date))
days_to_expire=$((seconds_to_expire / (60 * 60 * 24)))
echo $days_to_expire
else
# Erro ao baixar informação do certificado.
echo -2
exit 2;
fi