Ok, I'm fairly new to bash scripting, but this is the issue I am experiencing (intermittently, not every time my script is run):
2 files in source directory
2 files in destination directory, same filenames as files in source.

cp source/*.* destination/*.*

cp command returns success (0 return code, checked by $?), yet suddenly there's only 1 file in the destination directory.

Any ideas? I'm completely stuck!

This is the code in question:
Code:
function transferfiles {
#$1 = "cp" or "mv"
#$2 = source files
#$3 = destination files

echo "***********************************************************" | tee -a $logfile
chk_fil=`ls $2/*.txt | wc -l`
echo Ready to transfer $chk_fil files... | tee -a $logfile
echo $1 from $2/ to $3 | tee -a $logfile
echo $chk_fil files | tee -a $logfile
echo >> $logfile

echo Source directory listing: >> $logfile
ls -l $2/*.txt >> $logfile
echo >> $logfile

echo Executing command >> $logfile
#here is where we actually execute the command
$1 $2/*.txt $3 | tee -a $logfile
#Check exit value, if non-zero write errors to screen and log
RC=$?
 if [ ${RC} != 0 ]
  then
    echo ERROR: $1 command returned error status ${RC} | tee -a $logfile
    return 1
  else
    echo Files moved OK | tee -a $logfile
    echo Destination directory listing: >> $logfile
    ls -l $3*.txt >> $logfile
    echo >> $logfile
 fi
 
 echo Checking files have copied properly... | tee -a $logfile
 cd $2
 for file in *.txt
 do
 if [ ! -e "$3$file" ]
 then
 echo "ERROR: File is missing: $file"  | tee -a $logfile
 return 2
 else
 echo "File found: $file"  | tee -a $logfile
 echo "Removing file from source dir" | tee -a $logfile
 rm $2/$file | tee -a $logfile
 continue
 fi
 done

 return 0
}

#File path and name to write output log to
logfile=/logdir/log/SAS_file_move_hourly.log
#Base directory for SAS outputs
stpdir=/stp
#Base directory on NAS drive
outdir=/outdir
errorcount=0
transferfiles cp $stpdir/report1 $outdir/report1/
errorcount=$[$errorcount+$?]
exit $errorcount
I've stripped the above out of the full code, and renamed a coupla things, but otherwise that's the issue I'm having.

In case it's any help, this is the log output for the last time it errored:

Code:
Ready to transfer 2 files...
cp from /stp/report1/ to /outdir/report1/
2 files

Source directory listing:
-rw-rw-rw-   1 ****** ****** 17 Feb 10 15:14 /stp/report1/last_update_time.txt
-rw-rw-rw-   1 ****** ****** 1489719 Feb 10 15:14 /stp/report1/nv_output.txt

Executing command
Files moved OK
Destination directory listing:
-rw-rw-rw-   1 ****** ****** 17 Feb 10 15:16 /outdir/report1/last_update_time.txt

Checking files have copied properly...
File found: last_update_time.txt
Removing file from source dir
ERROR: File is missing: nv_output.txt
I've blanked out the username and group from the ls listing for security reasons.

I don't know if it makes a difference in this case, but I believe the outdir and the source dir are on different systems that are mapped to the one system so they all appear as directories in the heirarchy. I don't know enough about bash to find out / provide much more detail than that tho.

Hope someone can help!
~Shiv