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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with shell script: cp command not working, but mv command works...
# 1  
Old 04-12-2011
Question 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. Smilie

Code:
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.


Code:
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. Smilie

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.
# 2  
Old 04-12-2011
scripts are seem like correct.Smilie
* 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

3. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

4. Shell Programming and Scripting

Paste command not working in shell script

Hai , When i use paste command in command prompt its giving expected output but not in the script. Below is the example. $cat file 1 2 3 $cat file1 4 5 6 $paste -d ':' file file1 1:4 2:5 3:6 but when i used the same command in script its giving the output as below : 1 2 3 (3 Replies)
Discussion started by: Subbu123
3 Replies

5. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

6. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

7. Shell Programming and Scripting

CD command not working in shell script

Hello All, I have tried many permutaion combinations in my shell script but cd command is not working in shell script. Can any one help me out in this. Below is my script. ############ #!/bin/sh set -x on BASE_DIR=/etc/init.d export BASE_DIR cd $BASE_DIR ############# but its... (8 Replies)
Discussion started by: ajaincv
8 Replies

8. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

9. Shell Programming and Scripting

awk command not working from the shell script

Hi, When i run the below command i am able to get the output. awk '/BEGIN DSSUBRECORD/{c=3;next}c-->0' abc.txt | awk '/END DSSUBRECORD/{exit}{print}' | awk '/Owner/{exit}{print}' | awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}' Output: Name "file_name", ... (5 Replies)
Discussion started by: onesuri
5 Replies

10. Shell Programming and Scripting

cd command is not working in my shell script

Hi, Following is my shell script. #!/bin/tcsh view=$1 image=$2 objfld="obj-ppc-$image" echo $view echo $image echo $objfld echo "cleartool setview $view" cleartool setview $view; cd `cd /vob/ios/sys`; In this "cd" is not working and not getting any error. my shell is "tcsh"... (3 Replies)
Discussion started by: amitrajvarma
3 Replies
Login or Register to Ask a Question