如何发送 openssl s_client -connect stdout 和 stderr 到 /dev/null?
How to send openssl s_client -connect stdout and stderr to /dev/null?
我有以下 bash 脚本来检查 Apache 中是否存在给定的 SSL 客户端证书。
#!/bin/bash
cert=
echo | openssl s_client -connect localhost:443 | grep -q $cert > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo $cert "client cert already exist"
else
#Create a new client cert in Apache
fi
即使我将 openssl 命令的 stdout 和 stderr 发送到 /dev/null,该命令仍然向控制台显示以下错误!
depth=3 C = OM, O = ORG, OU = For Staging, CN = ROOT CA - 1 verify error:num=19:self signed certificate in certificate chain verify return:0 /C =om/O=o/CN=MY_CERT
完成
问题是您实际上并没有将 openssl
的标准错误发送到 /dev/null
,而是 grep
的。
要将 openssl
的标准错误发送到 /dev/null
,您需要将重定向放入与 openssl
调用相同的管道部分。当您使用 grep -q
时,您不需要在 grep
.
上进行任何 I/O 重定向
应该这样做:
echo | openssl s_client -connect localhost:443 2>/dev/null | grep -q $cert
我有以下 bash 脚本来检查 Apache 中是否存在给定的 SSL 客户端证书。
#!/bin/bash
cert=
echo | openssl s_client -connect localhost:443 | grep -q $cert > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo $cert "client cert already exist"
else
#Create a new client cert in Apache
fi
即使我将 openssl 命令的 stdout 和 stderr 发送到 /dev/null,该命令仍然向控制台显示以下错误!
depth=3 C = OM, O = ORG, OU = For Staging, CN = ROOT CA - 1 verify error:num=19:self signed certificate in certificate chain verify return:0 /C =om/O=o/CN=MY_CERT 完成
问题是您实际上并没有将 openssl
的标准错误发送到 /dev/null
,而是 grep
的。
要将 openssl
的标准错误发送到 /dev/null
,您需要将重定向放入与 openssl
调用相同的管道部分。当您使用 grep -q
时,您不需要在 grep
.
应该这样做:
echo | openssl s_client -connect localhost:443 2>/dev/null | grep -q $cert