我正在编写一个简单的脚本来检查网站的证书是否有效。但是,当我尝试在终端中运行代码时,我收到一条错误消息,指出openssl
找不到该命令。这是代码:
if true | openssl s_client -connect www.google.com:443 2>/dev/null | \
openssl x509 -noout -checkend 0; then
echo "Certificate is not expired"
else
echo "Certificate is expired"
fi
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此代码时,我收到以下输出:
if true | openssl s_client -connect www.google.com:443 2>/dev/null | \
openssl x509 -noout -checkend 0; then
echo "Certificate is not expired"
else
echo "Certificate is expired"
fi
Run Code Online (Sandbox Code Playgroud)
代码运行,但它不能识别openssl
为有效命令,因此它跳过提到这一点的代码行,并默认输出“证书已过期”。
使用时sudo apt-get install openssl
我收到此消息:
./check-certificates.sh: line 6: openssl: command not found
Certificate is expired
Run Code Online (Sandbox Code Playgroud)
所以看起来openssl
已经成功安装了。我不知道如何解决这个问题 …