Hi everyone,
I've been racking my brains for ages on this and need your help/advice.
I am writing a script that is reading in file to process and putting them into a temporary file. The loop starts and the script gets the first file name, does what i needs to do (copy it) and then returns to the top of the loop for the next file. Due to the nature of the system While inside the read line loop I have to get the next sequence number from another file which is generated by an export of an oracle table. This is then appeneded to the filename.
The problem here is that as soon as I try and read in the sequence number any subsequent files are blank. The code im using is
ifdtime=`date +%d%m%y%H%M` ; export ifdtime
LOG_FILE="/test/ohms/jobs/log/if.log" ; export LOG_FILE
LOGDIR="/test/ohms/jobs/log" ; export LOG_DIR
LOCKFILE=/tmp/KSJOBLOCK_${ORACLE_SID} ; export LOCKFILE
FILESIN=/servintftest/input/orders ; export FILESIN
runtime=`date "+%H:%M"`
rundate=`date "+%d/%m/%y"`
>$LOG_FILE
## Functions - the 2 reads are becuase oracle generates a blank line at start
get_seqno ()
{
exec < /home/interfac/scripts/seq.num;
read mark
read mark
seqno=$mark
echo $seqno
}
## Check to see if any files exist if not then abort the interface
if [ `ls -1 /servintftest/input/orders/ORDER* | wc -l` = 0 ]
then
echo "ERROR: No Files Received"
echo "${ifdtime} : ERROR: No Files Received" >>$LOG_FILE
exit
fi
## Files must exist if we got this far so read all filenames into a temp file
rm $LOGDIR/ohms_files
>$LOGDIR/ohms_files
ls -1 $FILESIN/ORDER*|cut -c28- >> $LOGDIR/ohms_files
## Now that we have the list lets process the files one by one
exec < $LOGDIR/ohms_files;
while read line
do
set - $line
## Get the last sequence number from the external system table
get_seqno
## Now copy the file but change the filename to ohmsjobs and seq no
echo "Copying file..."
cp -p $FILESIN/$1 /test/ohms/input/ohmsjobs.${seqno}
#cp -p /test/ohms/input/$1 /test/ohms/jobs/backup/ohmsjobs.${seqno}.${ifdtime}
if [ -f /test/ohms/input/ohmsjobs.${seqno} ]
then
echo "${ifdtime} : OHMS file copied $1 renamed to ohmsjobs.$seqno" >> $LOG_FILE
echo "${ifdtime} : OHMS file copied $1 renamed to ohmsjobs.$seqno"
sleep 5
#rm $FILESIN/$1fi
## Interface must have completed and a backup copy has been taken so delete
#rm /test/ohms/input/$1
done
Any help you can give would be appreciated
Regards,
Mark