for 루프에서 xmlstarlet을 사용하여 동일한 태그가 여러 번 나타나는 중에서 속성 값을 선택하려고 하는데 반복의 $i가 예상한 대로 값을 가져오지 않습니다. "$i"로 인용하고 있습니다. -m 문자 ' '로 이스케이프 처리했지만 올바르게 해석하지 못하는 것 같습니다. 이 문제를 어떻게 해결해야 할지 모르겠습니다.
for i in {1..16};
do
FTRSERVER=`xmlstarlet sel -t -m '//JOB[\"$i\"]' -v './AUTOEDIT2[@NAME="%%FTP-RHOST"]/@VALUE' ~testhwa/FTPJobstable007.xml`
done
입력 XML 예, JOB 태그가 여러 번 나타납니다.
<JOB
ACTIVE_TILL="20141124"
APPLICATION="CTDS0320"
APPL_FORM="AFT"
APPL_TYPE="FILE_TRANS"
APPL_VER="6.1.01"
APR="1"
AUG="1"
AUTHOR="wyy"
AUTOARCH="0"
CHANGE_DATE="20190403"
CHANGE_TIME="141554"
CHANGE_USERID="ecsadmin"
CM_VER="610"
CONFIRM="0"
CREATION_DATE="20190328"
CREATION_TIME="105555"
CREATION_USER="singhm7"
CRITICAL="0"
CYCLIC="0"
CYCLIC_TOLERANCE="0"
CYCLIC_TYPE="Interval"
DAYS_AND_OR="OR"
DEC="1"
DESCRIPTION="Processes Source data files FTP from Source System"
DOCLIB="/prod/appl/ctds/Doc"
DOCMEM="energent_billing_delta.doc"
FEB="1"
GROUP="@CTDS-BW"
IND_CYCLIC="START"
INTERVAL="00000M"
JAN="1"
JOBNAME="energent_billing_delta-FTP"
JUL="1"
JUN="1"
MAR="1"
MAXDAYS="0"
MAXRERUN="0"
MAXRUNS="0"
MAXWAIT="7"
MAY="1"
MEMLIB="Not in use for application jobs"
MEMNAME="energent_billing_delta-FTP"
MULTY_AGENT="N"
NODEID="vprv0320"
NOV="1"
OCT="1"
OWNER="ctds_energent"
PARENT_TABLE="@CTDS"
PRIORITY="AA"
RETRO="0"
RULE_BASED_CALENDAR_RELATIONSHIP="OR"
SEP="1"
SHIFT="IGNOREJOB"
SHIFTNUM="+00"
SYSDB="0"
TASKTYPE="Job"
USE_INSTREAM_JCL="N"
WEEKSCAL="BCD-Y">
<INCOND AND_OR="AND" NAME="CTDS0320-ENERGENT-BILLING-DELTA-OK" ODATE="ODAT"/>
<OUTCOND NAME="CTDS0320-ENERGENT-BILLING-DELTA-FTP" ODATE="ODAT" SIGN="ADD"/>
<AUTOEDIT2 NAME="%%FTP-ACCOUNT" VALUE="ctds_energent"/>
<AUTOEDIT2 NAME="%%FTP-LOSTYPE" VALUE="Unix"/>
<AUTOEDIT2 NAME="%%FTP-LUSER" VALUE="ctds"/>
<AUTOEDIT2 NAME="%%FTP-ROSTYPE" VALUE="Windows"/>
<AUTOEDIT2 NAME="%%FTP-RUSER" VALUE="[email protected]"/>
<AUTOEDIT2 NAME="%%FTP-LPATH1" VALUE="/prod/appl/ctds/Publish/ENERGENT/*"/>
<AUTOEDIT2 NAME="%%FTP-RPATH1" VALUE="/\Business Intelligence-Gas Consumption\Energent\Outgoing\Gas Consumption\"/>
<AUTOEDIT2 NAME="%%FTP-PATH" VALUE="Not in use for application jobs"/>
<AUTOEDIT2 NAME="%%FTP-USE_DEF_NUMRETRIES" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-RPF" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-CLEAR_ALL" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-CONNTYPE2" VALUE="FTP"/>
<AUTOEDIT2 NAME="%%FTP-CONNTYPE1" VALUE="LOCAL"/>
<AUTOEDIT2 NAME="%%FTP-LHOST" VALUE="Local"/>
<AUTOEDIT2 NAME="%%FTP-RHOST" VALUE="hdq-nt164"/>
<AUTOEDIT2 NAME="%%FTP-LPASSIVE" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-RPASSIVE" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD1" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD2" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD3" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD4" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD5" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRANSFER_NUM" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TYPE1" VALUE="A"/>
<AUTOEDIT2 NAME="%%FTP-TYPE2" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-TYPE3" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-TYPE4" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-TYPE5" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-UNIQUE1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT1" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TRIM1" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM2" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM3" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM4" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM5" VALUE="1"/>
</JOB>
<JOB
ACTIVE_TILL="20141124"
APPLICATION="CTDS-VPRV0342"
APPL_FORM="AFT"
APPL_TYPE="FILE_TRANS"
APPL_VER="6.1.01"
APR="1"
AUG="1"
AUTHOR="wyy"
AUTOARCH="0"
CHANGE_DATE="20190716"
CHANGE_TIME="233201"
CHANGE_USERID="pahwar"
CM_VER="610"
CONFIRM="0"
CREATION_DATE="20190611"
CREATION_TIME="072632"
CREATION_USER="pahwar"
CRITICAL="0"
CYCLIC="0"
CYCLIC_TOLERANCE="0"
CYCLIC_TYPE="Interval"
DAYS_AND_OR="OR"
DEC="1"
DESCRIPTION="Processes Source data files FTP from Source System"
DOCLIB="/prod/appl/ctds/Doc/"
DOCMEM="energent_billing_delta.doc"
FEB="1"
GROUP="@CTDS-BW"
IND_CYCLIC="START"
INTERVAL="00000M"
JAN="1"
JOBNAME="energent_billing_delta-FTP"
JUL="1"
JUN="1"
MAR="1"
MAXDAYS="0"
MAXRERUN="0"
MAXRUNS="0"
MAXWAIT="7"
MAY="1"
MEMLIB="Not in use for application jobs"
MEMNAME="energent_billing_delta-FTP"
MULTY_AGENT="N"
NODEID="vprv0342"
NOV="1"
OCT="1"
OWNER="ctds_energent"
PARENT_TABLE="@CTDS-VPRV0342"
PRIORITY="AA"
RETRO="0"
RULE_BASED_CALENDAR_RELATIONSHIP="OR"
SEP="1"
SHIFT="IGNOREJOB"
SHIFTNUM="+00"
SYSDB="0"
TASKTYPE="Job"
USE_INSTREAM_JCL="N"
WEEKSCAL="BCD-Y">
<INCOND AND_OR="AND" NAME="V0342-ENERGENT-BILLING-DELTA-OK" ODATE="ODAT"/>
<OUTCOND NAME="V0342-ENERGENT-BILLING-DELTA-FTP" ODATE="ODAT" SIGN="ADD"/>
<AUTOEDIT2 NAME="%%FTP-ACCOUNT" VALUE="ctds_energent"/>
<AUTOEDIT2 NAME="%%FTP-LOSTYPE" VALUE="Unix"/>
<AUTOEDIT2 NAME="%%FTP-LUSER" VALUE="ctds"/>
<AUTOEDIT2 NAME="%%FTP-ROSTYPE" VALUE="Windows"/>
<AUTOEDIT2 NAME="%%FTP-RUSER" VALUE="[email protected]"/>
<AUTOEDIT2 NAME="%%FTP-LPATH1" VALUE="/prod/appl/ctds/Publish/ENERGENT/*"/>
<AUTOEDIT2 NAME="%%FTP-RPATH1" VALUE="/\Business Intelligence-Gas Consumption\Energent\Outgoing\Gas Consumption\"/>
<AUTOEDIT2 NAME="%%FTP-PATH" VALUE="Not in use for application jobs"/>
<AUTOEDIT2 NAME="%%FTP-USE_DEF_NUMRETRIES" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-RPF" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-CLEAR_ALL" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-CONNTYPE2" VALUE="FTP"/>
<AUTOEDIT2 NAME="%%FTP-CONNTYPE1" VALUE="LOCAL"/>
<AUTOEDIT2 NAME="%%FTP-LHOST" VALUE="Local"/>
<AUTOEDIT2 NAME="%%FTP-RHOST" VALUE="hdq-nt164"/>
<AUTOEDIT2 NAME="%%FTP-LPASSIVE" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-RPASSIVE" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD1" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD2" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD3" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD4" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-UPLOAD5" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRANSFER_NUM" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TYPE1" VALUE="A"/>
<AUTOEDIT2 NAME="%%FTP-TYPE2" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-TYPE3" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-TYPE4" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-TYPE5" VALUE="I"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-MINSIZE5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TIMELIMIT5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-UNIQUE1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-IF_EXIST5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT1" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-SRCOPT5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-DSTOPT5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME1" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME2" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME3" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME4" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-ABSTIME5" VALUE="0"/>
<AUTOEDIT2 NAME="%%FTP-TRIM1" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM2" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM3" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM4" VALUE="1"/>
<AUTOEDIT2 NAME="%%FTP-TRIM5" VALUE="1"/>
</JOB>
<JOB
감사합니다, Sriram.V
답변1
각 FTP 서버 주소에 대해 전체 XML 파일을 한 번씩 구문 분석하려는 이유를 정말로 이해하지 못합니다. 추출하는 것이 더 합리적일 것입니다.모두서버 이름을 입력하고 이를 반복합니다.
xmlstarlet sel -t -v '//JOB/AUTOEDIT2[@NAME="%%FTP-RHOST"]/@VALUE' -nl file.xml |
while IFS= read -r ftpserver; do
# do things with "$ftpserver"
done
처음 16개의 작업만 확보해야 하는 경우:
xmlstarlet sel -t -v '//JOB[position()<=16]/AUTOEDIT2[@NAME="%%FTP-RHOST"]/@VALUE' -nl file.xml |
while IFS= read -r ftpserver; do
# do things with "$ftpserver"
done
코드의 주요 문제는 작은따옴표로 묶인 문자열 내에서 쉘 변수를 사용하려고 한다는 것입니다. 쉘은 작은따옴표로 묶인 문자열 내의 변수를 확장하지 않습니다.