2
我试图运行.sh文件,通过keytool命令将证书放入〜/ .java/deployment/deployment.properties文件中描述的每个jre/lib/security/cacert文件中。在循环内部评估shell变量
但得到错误“密钥库参数不能为空”在
sudo bash -c keytool -import -v -trustcacerts -alias test-cert -file ./test.cer -keystore ${resultPath};
我已经尝试过使用eval和“$()”符号 - 但这种失败了。我该如何解决这个问题?
#!/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 : ${resultPath} somehow is empty
sudo bash -c keytool -import -v -trustcacerts -alias test-cert -file ./test.cer -keystore ${resultPath};
;;
(*)
;;
esac
fi
done < "$FILE"
UPDATE:通过庆典-vx行书./script.sh显示此输出:
#!/bin/bash
PATTERN=deployment\.javaws\.jre\.[0-9]*\.path
+ PATTERN='deployment.javaws.jre.[0-9]*.path'
FILE=~/.java/deployment/deployment.properties
+ FILE=/home/sanya/.java/deployment/deployment.properties
sep='='
+ sep==
trail=lib/security/cacerts
+ 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 : ${resultPath} somehow is empty
sudo keytool -importcert -v -trustcacerts -alias test -file ./test.cer -keystore ${resultPath};
;;
(*)
;;
esac
fi
done < "$FILE"
+ read line
+ printf '%s\n' '#deployment.properties'
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ read line
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ printf '%s\n' '#Sat Sep 06 10:48:49 MSK 2014'
+ read line
+ printf '%s\n' deployment.modified.timestamp=1409986129309
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ read line
+ printf '%s\n' deployment.version=7.21
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ read line
+ printf '%s\n' deployment.browser.path=/usr/bin/firefox
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ read line
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ printf '%s\n' '#Java Deployment jre'\''s'
+ read line
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ printf '%s\n' '#Sat Sep 06 10:48:49 MSK 2014'
+ read line
+ printf '%s\n' deployment.javaws.jre.0.registered=true
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ read line
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ printf '%s\n' deployment.javaws.jre.0.platform=1.7
+ read line
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ printf '%s\n' deployment.javaws.jre.0.osname=Linux
+ read line
+ grep -q 'deployment.javaws.jre.[0-9]*.path'
+ printf '%s\n' deployment.javaws.jre.0.path=/usr/lib/jvm/java-7-oracle/jre/bin/java
+ case $line in
+ after=/usr/lib/jvm/java-7-oracle/jre/bin/java
+ resultPath=/usr/lib/jvm/java-7-oracle/jre/lib/security/cacerts
+ sudo keytool -importcert -v -trustcacerts -alias test -file ./test.cer -keystore /usr/lib/jvm/java-7-oracle/jre/lib/security/cacerts
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
+ read line
错误线
Enter keystore password: keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect
显示,因为用户应该密钥存储文件输入密码,但是当这个脚本运行时,不会提示输入密码的提示。我该如何解决这个问题?
用'bash -vx脚本'运行脚本并检查输出 – 2014-09-05 19:05:24
不幸,我只能使用sh ./script.sh来运行脚本。 – 2014-09-05 19:24:19
但你的“sh-bang”行是'!#/ bin/bash'。你尝试过'sh -x。/ script.sh'还是不能使用它?你可以编辑你的脚本或从/ tmp目录运行它的编辑副本吗?然后在该行后面的'sudo'行和'set -x'之上添加'set -x'。祝你好运。 – shellter 2014-09-05 19:52:43