检查密钥店里是否存在别名
我是外壳脚本的新手,我有一个用于使用KeyTool导入CERT和导入密钥库的脚本。这个脚本在吊舱内,有时候我必须重新启动吊舱
存在现有的进入别名服务器,覆盖? [否]:输入新别名 名称(返回此条目取消导入):
我知道有命令列出
keytool -list -keystore keystore.jks -storepass changeit -alias server
提供输出的
别名服务器,6月22日,2022年,私人按键, 证书指纹(SHA-256):AC:DC:12:...
对于不存在的别名,此命令给出了例外
keytool错误:java.lang.exception:别名不存在
如果存在键盘别名存在,如果不允许 keytool -importcert 命令,则可以编写检查吗?我可以比较任何可以与执行的返回代码?
谢谢
I am new to shell scripting, I have a script that is used to import cert and import keystore using keytool. This script is inside a Pod, there are times when I have to restart my pod and sometimes when this script runs I get this error
Existing entry alias server exists, overwrite? [no]: Enter new alias
name (RETURN to cancel import for this entry):
I know that there is command to list the alias
keytool -list -keystore keystore.jks -storepass changeit -alias server
which gives the output
server, Jun 22, 2022, PrivateKeyEntry,
Certificate fingerprint (SHA-256): AC:DC:12:...
for an alias it that is not there, this command gives an exception
keytool error: java.lang.Exception: Alias does not exist
Is there a way in which I can write a check if the an keystore alias exists, if not allow the keytool -importcert command to execute ? Are there any return codes that I can compare to move forward with the execution ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
$?
查找最后执行命令的返回值。0返回值意味着成功,否则,如果有例外,您会得到其他数字,然后再获得0。
edit
正如查尔斯·达菲(Charles Duffy)指出的
$?
不建议。您可以简单地使用
You can use
$?
to find the return value of the last executed command.0 return value means success, otherwise, in case of exception, you get a number other then 0.
EDIT
As Charles Duffy points out the use of
$?
is discouraged.You can simply use