对于我正在使用的服务器技术,可以通过运行一些命令行参数来手动将服务器加入到集合中。在某一时刻,控制台会提示您是否要接受证书链,您输入(y/n)
,命令就会继续运行。我正在尝试使该过程自动化,但在响应输入提示时遇到了障碍,并且在深入研究后听说这可能是 SSL 的事情,所以我不知道是否有不同的方法来做到这一点。
如果您手动执行此操作,则结果如下:
Joining the collective with target controller ...this may take a while
SSL trust has not been established with the target server
//certificate chain
Do you want to accept the above certificate chain? (y/n)
但是,两者:
echo "y y" | bash ./script.sh
//inside script.sh
echo "y y" | $(command)
最终得到以下回复:
Joining the collective with target controller ...this may take a while
SSL trust has not been established with the target server
//certificate chain
Input console is not available
Aborting join collective.
Error:
Unable to complete the MBean operation
Error: java.securit.cert.CertificateException: User has rejected the request to trust the
certificate chain
我希望有人能够阐明一种除了手动响应之外的方法
最佳答案
错误Input console is not available
表明目标程序期望与真实的终端通信,而不是管道(这是如果您尝试 echo
进入程序时得到的结果)。
在这种情况下,您将使用类似 expect
的内容来自动化程序。 ,它模拟真实的终端(使用伪终端),并且通常可以“欺骗”这样的程序,使其相信它们正在与真实的终端进行通信。 expect
可以让你在程序中输入任意命令。
参见Bash/Expect Script for SSH有关如何使用 Expect 的示例(此处用于自动化 ssh
)。
关于linux - 如何在 bash 脚本中获取控制台输入以使用 SSL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25772670/