익명 07:09

Adding a date in a filename in a kornshell script intermittently failing

Adding a date in a filename in a kornshell script intermittently failing

This command setting a file name in a shell script which runs repeatedly in both test and a production environment and has been running for years now but sometimes fails to create a name for the file. When it fails, it just leaves a dot and the file extension. The file extension varies.

I have edited the script to use a different file extension as people are getting hung up on the use of XML. The files do contain xml which is being sent to SmartComms to produce documents. There are different XML schemas. Each schema has its own file extension.

fextension=policy
bigFname=`date +"%Y-%m-%d-%H-%M-%S"`"."${fExtension}

So when I test it in a small script I get for example this:

2026-07-02-16-08-51.policy

But when the script auto-runs every five minutes sometimes it will generate afiel name like this:

.policy

Why would this now sometimes fail? So far it is only happening in some test environments.

I have now found the logs including an example of the error. They contain nothing useful.

This is the actual relevant code section:

# AK Batch up XML into a big XML
# Get the amount of XML to batch up from column NEXT_SEQ_NO in table TLLI_24006CONTAB where CONTROL_CODE = 'TB'
batchAMT=`sqlplus -s -L SAPIENS/$(LLPG0031) @"$RUNDATA""pisop/sysin/"getXMLcombineAmount.sql`
if (( $batchAMT > 0 ))
then
        # Loop through an unique list of the different file extensions in the working directory
        ls ${WORKINGDIR} | sed 's/.*\.//' | sort -u | while read fExtension
        do
                # Create the new filename
                bigFname=`date +"%Y-%m-%d-%H-%M-%S"`"."${fExtension}
                # Display some info
                echo "There are `ls ${WORKINGDIR}/*${fExtension} | wc -l` ${fExtension} files"
                echo "Batching up ${batchAMT} XML files into a big XML called ${WORKINGDIR}/${bigFname}"
                # Find files with the extension we are looking for and process batchAMT of them. "pretty print" them all with xmllint into bigFname and then delete them
######          find ${WORKINGDIR}/. ! -name . -prune -type f -name "*${fExtension}" | head -${batchAMT} | xargs -n${batchAMT} -I{} ksh -c "xmllint --format {} >>${WORKINGDIR}/${bigFname} && rm -v -f {}"
#######         find ${WORKINGDIR} -name "*${fExtension}" | head -${batchAMT} | xargs -n${batchAMT} -I{} ksh -c "iconv -f utf-8 -t utf-8 -c {};xmllint --format {} >>${WORKINGDIR}/${bigFname} && rm -v -f {}"
                find ${WORKINGDIR} -name "*${fExtension}" | head -${batchAMT} | while read batchFile
                do
                   iconv -f utf-8 -t utf-8 -c $batchFile -o $batchFile.conved
                   checkRC $? "iconv -f utf-8 -t utf-8 -c $batchFile -o $batchFile.conved" 0
                   mv $batchFile.conved $batchFile
                   xmllint --format $batchFile >>${WORKINGDIR}/${bigFname} && rm -v -f $batchFile
                   lintRC=$?
                   checkRC $lintRC "xmllint --format $batchFile >>${WORKINGDIR}/${bigFname} && rm -v -f $batchFile" 0
                   if (( $lintRC > 0 ))
                   then
                        mv $batchFile $ARCHIVEDIR/`basename $batchFile`.BAD
                   fi
                done
 
                # Count how many messages are in the big file
                messageCount=`grep '</transaction>' ${WORKINGDIR}/${bigFname} | wc -l`
                # Use the stream editor (sed) to edit the file in place.
                # -e '1!{/xml version/d}' (This command deleted all lines containing xml version, except from the first line. This leaves us with one xml declaration header)
                # -e '1a\<message>' (This command inserts a line with the text '<message>' after the first line
                # -e '$a\</message>' (This command inserts a line at the end of the file containing the text '</message>' the last two command wraps the small xml request in a new parent element 'message')
                sed -i -e '1!{/xml version/d}' -e '1a\<message count="\'"${messageCount}"'"\>' -e '$a\</message>' ${WORKINGDIR}/${bigFname}
 
                # Move the new big file to the inbound directory
                # Only move if the file is greater than 0
                # A size of zero means that the file is not a valid XML document for whatever reason
                if [ -s ${WORKINGDIR}/${bigFname} ]
                then
                        mv ${WORKINGDIR}/${bigFname} ${COPYTODIR}/.
                else
                        rm ${WORKINGDIR}/${bigFname}
                fi
 
                # Display some info
                echo "After combining the XML into a big XML there are now `ls ${WORKINGDIR}/*${fExtension} 2>/dev/null | wc -l` ${fExtension} files"
        done

This is the relevant section of the log file:

LLStripCR: Write file to </emerge/SYS/interface/thead/requests/inbound/LLS09330130.claim> and delete...
removed '/emerge/SYS/interface/thead/requests/holding/LLS09330130.claim'
LLStripCR: Processing of file </emerge/SYS/interface/thead/requests/holding/LLS09330130.claim> completed.
There are 1 claim files
Batching up 500 XML files into a big XML called /emerge/SYS/interface/thead/requests/combineXML/.claim
removed '/emerge/SYS/interface/thead/requests/combineXML/LLS09330130.claim'
After combining the XML into a big XML there are now 0 claim files
LLStripCR: Processing completed at
:LLSTRIPCR: file: INPUTYEAR=2006 bytes=0
:LLSTRIPCR: file: INPUTPYEAR=2005 bytes=0
:LLSTRIPCR: file: SAPDBID=ll bytes=0
:LLSTRIPCR: Begin Job=LLSTRIPCR
:LLSTRIPCR: /emerge/SYS/doclistener/LLStripCR.sh
:LLSTRIPCR: Arguments:
:LLSTRIPCR: RUNLIBS=/emerge/SYS/
:LLSTRIPCR: RUNDATA=/emerge/SYS/
:LLSTRIPCR: JTMP=jobtmp/LLSTRIPCR SYOT=sysout/LLSTRIPCR
:LLSTRIPCR: RUNDATE=
ERROR: ld.so: object 'libjsig.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
:LLSTRIPCR: file: IN=pisop/sysin/LLStripCRa bytes=82

Specifically, the problem can bee seen in the line that says:

Batching up 500 XML files into a big XML called /emerge/SYS/interface/thead/requests/combineXML/.claim


Top Answer/Comment:

Comment: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다