#!/bin/ksh
print -n "\nEnter the client ID : "
read clientID
print $clientID
data=$(grep jms/erms/$clientID /export/home/a0706838/test.txt;)
print "\n $data"
getClientID=$(echo "$data" | awk '{print $8}'| perl -lne 'print substr($_,0,5)';)
print "$getClientID"
getClientID1=$(echo "$data" | awk '{print $9}'| perl -lne 'print substr($_,19,5)';)
getClientID2=$(echo "$data" | awk '{print $15}'| perl -lne 'print substr($_,20,5)';)
if [ -z "$data" ]
then
print "Setup is not present on $i for $clientID"
print "Please login to server $i manually and check for the client $clientID on path /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA/ in resources.xml file"
print "==============================================================================================================================================================="
elif [ -z "$getClientID" ] | [ -z "$getClientID1" ] | [ -z "$getClientID2" ]
then
print "Setup for client $clientID has been not done correctly on server $i. Please contact WasTech team for this."
print "==============================================================================================================="
else
print "\n"
print "Setup is valid on $i for $clientID for CellV70_TBA path"
print "====================================================================================================="
fi
测试.txt 文件
<factories xmi:type="resources.jms.mqseries:MQQueue" xmi:id="MQQueue_1549053088921" name="ERMS Message Queue - 16661" jndiName="jms/erms/16662" persistence="QUEUE_DEFINED" priority="QUEUE_DEFINED" specifiedPriority="0" expiry="UNLIMITED" specifiedExpiry="0" baseQueueName="TBAT.16662.SPM.ERMSIN" CCSID="1208" useNativeEncoding="true" integerEncoding="Normal" decimalEncoding="Normal" floatingPointEncoding="IEEENormal" targetClient="MQ" queueManagerPort="1414" sendAsync="QUEUE_DEFINED" readAhead="QUEUE_DEFINED">
答案1
||
shell 中写的是逻辑“或” 。管道 ( |
) 是另一回事。特别是管道的退出状态是最后一个命令的退出状态,因此这里仅适用最后一个条件。
[ -z "$getClientID" ] | [ -z "$getClientID1" ] | [ -z "$getClientID2" ]
应该
[ -z "$getClientID" ] || [ -z "$getClientID1" ] || [ -z "$getClientID2" ]
您对给定 XML 的解析也是有问题且脆弱的,但我真的不能说太多,因为您没有告诉我们您要从该文件中解析什么(并且这不是问题的重点) )。如果name
属性值以添加更多单词或删除某些单词的方式发生变化,它可能会中断。它还取决于属性的顺序。从语义上讲,顺序对于 XML 格式并不重要,属性之间的空白数量或类型也不重要。