Process files in a directory and move them

I have a directory e2e_ms_xfer/cent01
this contains the multiple files some of which will be named below with unique date time stamps
e2e_ms_edd_nom_CCYYMMDD_HHMM.csv
What I want to do is in a loop
1) Get the oldest file
2) Rename
3) Move it up one level from e2e_ms_xfer/cent01 to /e2e_ms_xfer
3) Process it
4) Move it down 2 levels to e2e_ms_xfer/cent01/done
4) Exit loop

This is what I have below but it does not do step 2 it says it cannot find files of that name although I have put 5 unique
e2e_ms_edd_nom_CCYYMMDD_HHMM.csv in the directory.

#
#
# Control the Unix processing cycle for uploading
# M+S Nomiated Delivery Days into the E2E database.
#
# 1.0 AM 13/09/2013 Initial Version
#
set +xv
 
# Execute the .profile (coz cron doesn't)
. ~/.profile
 
# Library functions
. $( dirname $0 )/common_functions.ksh
 
THIS=$( basename $0 )
 
fn_banner "Process M+S Nominated Delivery Days files"
 
echo "Starting: $(date)"
fn_writeTrace "starting"
 
 
# Local variables
bookmark="10"
TODAY=$(date "+%Y%m%d")
D_EXTTAB=/e2e_ms_xfer
MASK=e2e_ms_edd_nom*
D_WORK=$XFMSC
D_DONE=$XFMSZ
JOBNAME=$( echo $THIS | cut -f1 -d. )
 
 
fileCount=0
 
# Oracle
bookmark="20"
fn_oraenv
 
# Good to go
bookmark="30"
runControl=1
 
while [ $runControl -eq 1 ]
do
cd $D_WORK
 
 
# Are there any files?
bookmark="35"
fileFound=0
ls -1 $MASK > /dev/null 2>&1
if [ $? -eq 0 ]
then
# Oldest file
bookmark="37"
fileName=$( ls -1 $MASK | head -n 1 )
mv filename e2e_ms_edd_nom.csv
 
let fileCount=fileCount+1
fileFound=1
 
# Move the file to where the ext.tables expect
bookmark="40"
mv $XFMSC/e2e_ms_edd_nom.csv $XFMS
 
# Invoke the Oracle process to upload the data
#
bookmark="50"
fn_oraenv
sqlplus $OCS @$SQL/exec_pull_nom_del_date.sql
 
# Move the file to 'done'
#
bookmark="60"
mv $XFMS/e2e_ms_edd_nom.csv $XFMSZ
 
fi # file found
 
 
fn_setHeartbeat $JOBNAME
 
done # while
 
# All done - Cleanup and exit
#
bookmark="70"
fn_cleanup
echo "Complete: $(date)"
fn_writeTrace "complete"
 
exit 0

Below is your post, with all the formatting displayed. May I ask you please to create a new thread without all the cruft. Please also use CODE tags for CODE blocks, not ICODE tags. Thanks.


I have a directory e2e\_ms_xfer/cent01
this contains the multiple files some of which will be named below with unique date time stamps
e2e\_ms\_edd\_nom\_CCYYMMDD_HHMM.csv
What I want to do is in a loop
1\) Get the oldest file
2\) Rename 
3\) Move it up one level from e2e\_ms_xfer/cent01 to /e2e\_ms_xfer
3\) Process it
4\) Move it down 2 levels to e2e\_ms_xfer/cent01/done
4\) Exit loop

This is what I have below but it does not do step 2 it says it cannot find files of that name although I have put 5 unique 
e2e\_ms\_edd\_nom\_CCYYMMDD_HHMM.csv in the directory.




```text
#
#
# Control the Unix processing cycle for uploading
# M+S Nomiated Delivery Days into the E2E database.
#
# 1.0 AM 13/09/2013 Initial Version
#
set +xv
 
# Execute the .profile (coz cron doesn't)
. ~/.profile
 
# Library functions
. $( dirname $0 )/common_functions.ksh
 
THIS=$( basename $0 )
 
fn_banner "Process M+S Nominated Delivery Days files"
 
echo "Starting: $(date)"
fn_writeTrace "starting"
 
 
# Local variables
bookmark="10"
TODAY=$(date "+%Y%m%d")
D_EXTTAB=/e2e_ms_xfer
MASK=e2e_ms_edd_nom*
D_WORK=$XFMSC
D_DONE=$XFMSZ
JOBNAME=$( echo $THIS | cut -f1 -d. )
 
 
fileCount=0
 
# Oracle
bookmark="20"
fn_oraenv
 
# Good to go
bookmark="30"
runControl=1
 
while [ $runControl -eq 1 ]
do
cd $D_WORK
 
 
# Are there any files?
bookmark="35"
fileFound=0
ls -1 $MASK > /dev/null 2>&1
if [ $? -eq 0 ]
then
# Oldest file
bookmark="37"
fileName=$( ls -1 $MASK | head -n 1 )
mv filename e2e_ms_edd_nom.csv
 
let fileCount=fileCount+1
fileFound=1
 
# Move the file to where the ext.tables expect
bookmark="40"
mv $XFMSC/e2e_ms_edd_nom.csv $XFMS
 
# Invoke the Oracle process to upload the data
#
bookmark="50"
fn_oraenv
sqlplus $OCS @$SQL/exec_pull_nom_del_date.sql
 
# Move the file to 'done'
#
bookmark="60"
mv $XFMS/e2e_ms_edd_nom.csv $XFMSZ
 
fi # file found
 
 
fn_setHeartbeat $JOBNAME
 
done # while
 
# All done - Cleanup and exit
#
bookmark="70"
fn_cleanup
echo "Complete: $(date)"
fn_writeTrace "complete"
 
exit 0
```