Mic*_*ash 3 scripting bash openssl command-not-found
我正在编写一个简单的脚本来检查网站的证书是否有效。但是,当我尝试在终端中运行代码时,我收到一条错误消息,指出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
已经成功安装了。我不知道如何解决这个问题 - 有人有什么想法吗?
根据要求,这里是输出apropos openssl | grep "OpenSSL command line tool"
:
openssl (1ssl) - OpenSSL command line tool
Run Code Online (Sandbox Code Playgroud)
并且locate openssl | grep /usr/bin
:
usr/bin/openssl
Run Code Online (Sandbox Code Playgroud)
请注意错误消息中的额外空间:
./check-certificates.sh: line 6: openssl: command not found
Run Code Online (Sandbox Code Playgroud)
这意味着 shell 正在寻找的命令不是openssl
,而是 openssl
,可能预先准备了一个牢不可破的空间。
您需要编辑脚本以确保之前的空间openssl
是“正常”空间,甚至删除它。
请参阅此命令为何不起作用:“ps aux | grep xscreensaver”以获取更多信息的类似实例。