Shell 命令未在 while 循环内要求输入密码

Shell 命令未在 while 循环内要求输入密码

我正在尝试运行 .sh 文件,通过 keytool 命令将证书放入 ~/.java/deployment/deployment.properties 文件中描述的每个 jre/lib/security/cacert 文件中。

#!/bin/bash

PATTERN=deployment\.javaws\.jre\.[0-9]*\.path
FILE=~/.java/deployment/deployment.properties
sep='='
trail=lib/security/cacerts

#Traverse file line by line
while read line ; do

  #If line matches pattern
  if printf %s\\n "${line}" | grep -q "${PATTERN}"; then
    case $line in 
      (*"$sep"*)

        #Process line to get path for ../jre/lib/security/cacert file
        after=${line#*"$sep"};
        resultPath=${after%????????}${trail};

        #This fails : no password asked and IOException showed
        sudo bash -c keytool -import -v -trustcacerts -alias test-cert -file ./test.cer -keystore ${resultPath};

      ;;
      (*)
      ;;
    esac
  fi
done < "$FILE"

排队

sudo bash -c keytool -import -v -trustcacerts -alias test-cert -file ./test.cer -keystore ${resultPath};

应该要求输入密码:第一个 - 管理员密码,因为sudo第二个 -keystore密码。但是当我通过运行此脚本时 bash ./script.sh,shell 仅要求输入管理员密码,而没有keystore要求。结果。我收到此错误:

Enter keystore password:  keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect
java.io.IOException: Keystore was tampered with, or password was incorrect
    at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:772)
    at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55)
    at java.security.KeyStore.load(KeyStore.java:1214)
    at sun.security.tools.KeyTool.doCommands(KeyTool.java:885)
    at sun.security.tools.KeyTool.run(KeyTool.java:340)
    at sun.security.tools.KeyTool.main(KeyTool.java:333)
Caused by: java.security.UnrecoverableKeyException: Password verification failed
    at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:770)
    ... 5 more

当系统要求输入keystore密码时我该怎么办?

相关内容