help with shell script: cp command not working, but mv command works...

Hello.

I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct.

We have a script (ftp.script) which calls on another script (copy.script).
copy.script is expected to create a copy of the file called "newfile.mmddyy" from /usr/tmp/data to /usr/tmp/work.
the result is we are getting a zero return code from the cp command but when we do a file listing command, it says that the file does not exist. :frowning:

copy.script

#!/usr/bin/ksh

FILE_BKUP=Y
ADD_DATE_TIME_SUFFIX=N
filename=newfile.mmddyy
pathfile=/usr/tmp/data/$filename
WORKPATH=/usr/tmp/work
LOGPATH=/usr/tmp/logs


  if [[ "$FILE_BKUP" = 'Y' ]]
    then 
      if [[ "$ADD_DATETIME_SUFFIX" = 'Y' ]]
        then
          cp $pathfile $WORKPATH/$filename.$DATESTAMP
          rc=$?
        else 
          cp $pathfile $WORKPATH/$filename
          rc=$?
          echo `ls -latr $WORKPATH/$filename` >> $LOGPATH/script.log
      fi      
  fi     


result:
+ [[ Y = Y ]]
+ [[ N = Y ]]
+ cp /usr/tmp/data/newfile.mmddyy /usr/tmp/work/newfile.mmddyy
+ rc=0
+ ls -latr /usr/tmp/work/newfile.mmddyy
ls: 0653-341 The file /usr/tmp/work/newfile.mmddyy does not exist.

What we did was to have the ftp.script check on /usr/tmp/work directory if the file exists there. If it doesn't exist there, the script will create a copy of the file on another work directory, /usr/tmp/work2, using the cp command and then move the file from /usr/tmp/data to /usr/tmp/work.

ftp.script


     if [[ -a $workdir/$1 ]];
      then
        rm -f $datadir/$1            
      else
        cp $datadir/$1 $workdir2/$1.copied_by_script.ftp
        mv $datadir/$1 $workdir/$1

     fi

where datadir=/usr/tmp/data, workdir=/usr/tmp/work and workdir2=/usr/tmp/work2. /usr/tmp/work2 has a dir permission of 2775, owner is usrdcrd and group is usrdeliv.

Since the file does not exist on /usr/tmp/work directory, I'm expecting ftp.script to create a copy of the file on /usr/tmp/work2 and move the file from /usr/tmp/data to /usr/tmp/work. But it only moved the file from /usr/tmp/data to /usr/tmp/work, again, the cp command did not work. :eek:

By the way, the file came from a SAP server and sent to the AIX server. Once the file reaches AIX server, a script is executed. This script then calls on the ftp.script to start the processing of the file. The owner/permission/group of the file when it reached AIX is : permission of 660, owner is usradm1 and group is usrdeliv.

scripts are seem like correct.:rolleyes:

  • you can try safely umount and then mount and check any errors.
  • if your system use default fs structure , maybe /usr/ must be on separate mount on a device..and if you can, you can run fsck this device despite any fs errors.