Sponsored Content
Top Forums Shell Programming and Scripting help with shell script: cp command not working, but mv command works... Post 302512965 by udelalv on Tuesday 12th of April 2011 03:40:32 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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

9. 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

10. 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
PWD(1)							    BSD General Commands Manual 						    PWD(1)

NAME
pwd -- return working directory name SYNOPSIS
pwd [-L | -P] DESCRIPTION
The pwd utility writes the absolute pathname of the current working directory to the standard output. Some shells may provide a builtin pwd command which is similar or identical to this utility. Consult the builtin(1) manual page. The options are as follows: -L Display the logical current working directory. -P Display the physical current working directory (all symbolic links resolved). If no options are specified, the -P option is assumed. ENVIRONMENT
Environment variables used by pwd: PWD Logical current working directory. EXIT STATUS
The pwd utility exits 0 on success, and >0 if an error occurs. SEE ALSO
builtin(1), cd(1), csh(1), sh(1), getcwd(3) STANDARDS
The pwd utility conforms to IEEE Std 1003.1-2001 (``POSIX.1''). BUGS
In csh(1) the command dirs is always faster because it is built into that shell. However, it can give a different answer in the rare case that the current directory or a containing directory was moved after the shell descended into it. The -L option does not work unless the PWD environment variable is exported by the shell. BSD
April 12, 2003 BSD
All times are GMT -4. The time now is 11:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy