【发布时间】:2016-03-04 15:17:27
【问题描述】:
我一直在编写一个脚本来获取一些证书详细信息,而不是我的格式正在被熨平,当我尝试解析 EndDate="openssl s_client -connect $host:$port 2>/dev/null | openssl x509 -enddate -noout | grep "Not After" | awk '{print $4, $5, $7}'" 时,脚本现在挂起。
这是我目前正在编写的完整脚本以供参考,因为我刚刚掌握了脚本编写的窍门,所以其中大部分都被破解了。
# User input for the host or url of the certificate to check
echo "What host IP or URL certificate would you like to check: "
read host
# User input for the port number of the certificate to check
echo "What is the port number for the host's IP or URL: "
read port
# Input Verification post
echo "Host connection information = $host:$port"
# openssl expiration date checks for the week
echo "::Certificate expiration date::"
EndDate=`openssl s_client -connect $host:$port 2>/dev/null | openssl x509 - enddate -noout | grep "Not After" | awk '{print $4, $5, $7}'`
DatePlus7=`date -ud "+7 day" | awk '{print $2, $3, $6}'`
if [ "$EndDate" = "$DatePlus7"]
then
echo "Certificate has expired or will do so within 7 days!"
echo "(or is invalid/not found)"
else
echo "Certificate is good for another week!"
fi
最终我希望能够为管理员输出echo | openssl s_client -connect $host:$port 2>/dev/null | openssl x509 -enddate -noout,这出现在fi 语句之后。谁能帮我解决这个问题?
【问题讨论】:
-
过早地将 std-err 输出重定向到 /dev/null 通常是错误的。你知道它在哪里失败了吗?您是否尝试仅执行
openssl s_client -connect $host:$port并且如果那是干净的,则添加下一段,直到您看到问题。祝你好运。 -
如果您在脚本“挂起”时点击
ctrl-d,它会恢复并继续运行吗?您可能只需要强制s_client终止连接而不是等待输入。 -
所以我让脚本运行了相当长的时间,大约 10-12 分钟,如果我使用我的原版脚本不理会它就会完成。我也可以
ctrl-d并且它确实恢复了。如果我也只是使用适当的变量执行openssl s_client -connect $host:$port,它运行良好没有问题。 @shellter 我不确定它在管道中的哪个位置失败,因为我刚刚开始使用 bash。
标签: linux bash shell ssl openssl