【发布时间】:2020-07-23 10:51:54
【问题描述】:
我有一个文本文件,我想从该文本文件中逐一读取 URL,并检查它们是否在 30 天或更长时间内过期。
考试网址:
example01.example.com:8080
example02.example.com:8002
example03.example.com:8003
https://example04.example.com:8111
...
我有一个检查 SSL 证书到期日期的 Bash 脚本:
#!/bin/bash
TARGET="example01.example.com:8080";
DAYS=30;
echo "checking if $TARGET expires in less than $DAYS days";
expirationdate=$(date -d "$(: | openssl s_client -connect $TARGET -servername $TARGET 2>/dev/null \
| openssl x509 -text \
| grep 'Not After' \
|awk '{print $4,$5,$7}')" '+%s');
time=$(($(date +%s) + (86400*$DAYS)));
if [ $time -gt $expirationdate ]; then
echo "KO - Certificate for $TARGET expires in less than $DAYS days, on $(date -d @$expirationdate '+%Y-%m-%d')" ;
echo $TARGET on $(date -d @$expirationdate '+%Y-%m-%d') > expireEndpoint.txt;
else
echo "OK - Certificate expires on $(date -d @$expirationdate '+%Y-%m-%d')";
fi;
有些网址也是重复的。
【问题讨论】:
标签: linux bash for-loop awk sed