我有3个shell脚本
script1.sh
openssl genrsa -out ca-key.pem 2048;
openssl req -new -x509 -nodes -days 1000 -key ca-key.pem -out ca-cert.pem;
openssl req -newkey rsa:2048 -days 1000 -nodes -keyout server-key.pem -out server-req.pem;
openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem;
openssl req -newkey rsa:2048 -days 1000 -nodes -keyout client-key.pem -out client-req.pem;
openssl x509 -req -in client-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem;
script2.sh
if [ $# -ne 3 ]
then
# RETURN INVALID USAGE
GetBatchCredentials_Result="Error"
GetBatchCredentials_Reason="Invalid usage: . $0 ApplicationId Alias Logfile"
else
# CONTINUE PROCESSING WITH PARAMETERSLT
RSLT=`/www/inf/xxxx/inf_service_account/2.0/scripts/script2.sh $1 $2 $3`
eval "$RSLT";
fi
script3.sh
# SET UP INFRASTRUCTURE CLASSPATH
. /www/inf/xxxx/inf_service_account/2.0/scripts/script3.sh
PROP="-Dcom.xxxx.env.location.pdc=ITC"
# CALL JAVA GetBatchCredentials TO RETRIEVE THE SERVICE ACCOUNT CREDENTIALS
$JAVA_HOME/bin/java $PROP com.xxxx.inf.serviceaccount.batch.GetBatchCredentials $1 $2 $3
我的主管希望我将所有这3个脚本合并为一个,因为这里有3个单独的脚本没有意义。这三个脚本分别工作正常,但我首先尝试组合前两个脚本,并且当我执行此脚本时,我得到了evitng unexpecetd文件结束错误:
SCRIPT1 + script2.sh
#!/bin/ksh
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/inf-service-account-2.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf_crypto.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf_generics.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf_password_vault.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf-jmx-2.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf-utils-2.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf-env-2.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf-recovery-2.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf-throttle-2.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/inf-trans-2.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/javaee-api-6.0.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/db2jcc.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/db2jcc_license_cu.jar
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_service_account/2.0/dependencies/db2java.zip
export CLASSPATH
我使用以下脚本运行上述脚本:
testScript.sh
if [ $# -ne 3 ]
then
# RETURN INVALID USAGE
GetBatchCredentials_Result="Error"
GetBatchCredentials_Reason="Invalid usage: . $0 ApplicationId Alias Logfile"
else
#SET UP INFRASTRUCTURE CLASSPATH
. /www/inf/xxxx/inf_security_common/2.0/scripts/script3.sh
#CALL JAVA GetBatchCredentials TO RETRIEVE THE SERVICE ACCOUNT CREDENTIALS
RSLT='$JAVA_HOME/bin/java com.xxxx.inf.serviceaccount.batch.GetBatchCredentials $1 $2 $3'
eval "$RSLT";
fi
请帮我解决此错误。
答案 0 :(得分:0)
RSLT='$JAVA_HOME/bin/java com.xxxx.inf.serviceaccount.batch.GetBatchCredentials $1 $2 $3'
应该是:
RSLT=`$JAVA_HOME/bin/java com.xxxx.inf.serviceaccount.batch.GetBatchCredentials $1 $2 $3`
您已将原始脚本中的反引号更改为组合脚本中的单引号。
另一个区别。原script2.sh
有:
PROP="-Dcom.xxxx.env.location.pdc=ITC"
$JAVA_HOME/bin/java $PROP com.xxxx.inf.serviceaccount.batch.GetBatchCredentials $1 $2 $3
从$PROP
的调用中,新脚本缺少java
。它应该是:
RSLT=`$JAVA_HOME/bin/java -Dcom.xxxx.env.location.pdc=ITC com.xxxx.inf.serviceaccount.batch.GetBatchCredentials $1 $2 $3
答案 1 :(得分:0)
我不确定究竟是什么工作,但我使用vim命令删除并重新输入。新文件正在运行。这是我的新文件:
###############################################################################
if [ $# -ne 3 ]
then
# RETURN INVALID USAGE
GetBatchCredentials_Result="Error"
GetBatchCredentials_Reason="Invalid usage: . $0 ApplicationId Alias Logfile"
else
# SET UP INFRASTRUCTURE CLASSPATH
CLASSPATH=$CLASSPATH:/www/inf/xxxx/inf_security_common/2.0/inf-security-common-2.0.jar
export CLASSPATH
# TODO - This needs to be set internally.
PROP="-Dcom.xxxx.env.location.pdc=ITC"
# CALL JAVA GetBatchCredentials TO RETRIEVE THE SERVICE ACCOUNT CREDENTIALS
RSLT=`$JAVA_HOME/bin/java $PROP com.xxxx.inf.serviceaccount.batch.GetBatchCredentials $1 $2 $3`
eval "$RSLT";
fi