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
GIT-SH-SETUP(1) 						    Git Manual							   GIT-SH-SETUP(1)

NAME
git-sh-setup - Common Git shell script setup code SYNOPSIS
. "$(git --exec-path)/git-sh-setup" DESCRIPTION
This is not a command the end user would want to run. Ever. This documentation is meant for people who are studying the Porcelain-ish scripts and/or are writing new ones. The git sh-setup scriptlet is designed to be sourced (using .) by other shell scripts to set up some variables pointing at the normal Git directories and a few helper shell functions. Before sourcing it, your script should set up a few variables; USAGE (and LONG_USAGE, if any) is used to define message given by usage() shell function. SUBDIRECTORY_OK can be set if the script can run from a subdirectory of the working tree (some commands do not). The scriptlet sets GIT_DIR and GIT_OBJECT_DIRECTORY shell variables, but does not export them to the environment. FUNCTIONS
die exit after emitting the supplied error message to the standard error stream. usage die with the usage message. set_reflog_action Set GIT_REFLOG_ACTION environment to a given string (typically the name of the program) unless it is already set. Whenever the script runs a git command that updates refs, a reflog entry is created using the value of this string to leave the record of what command updated the ref. git_editor runs an editor of user's choice (GIT_EDITOR, core.editor, VISUAL or EDITOR) on a given file, but error out if no editor is specified and the terminal is dumb. is_bare_repository outputs true or false to the standard output stream to indicate if the repository is a bare repository (i.e. without an associated working tree). cd_to_toplevel runs chdir to the toplevel of the working tree. require_work_tree checks if the current directory is within the working tree of the repository, and otherwise dies. require_work_tree_exists checks if the working tree associated with the repository exists, and otherwise dies. Often done before calling cd_to_toplevel, which is impossible to do if there is no working tree. require_clean_work_tree <action> [<hint>] checks that the working tree and index associated with the repository have no uncommitted changes to tracked files. Otherwise it emits an error message of the form Cannot <action>: <reason>. <hint>, and dies. Example: require_clean_work_tree rebase "Please commit or stash them." get_author_ident_from_commit outputs code for use with eval to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit. create_virtual_base modifies the first file so only lines in common with the second file remain. If there is insufficient common material, then the first file is left empty. The result is suitable as a virtual base input for a 3-way merge. GIT
Part of the git(1) suite Git 2.17.1 10/05/2018 GIT-SH-SETUP(1)
All times are GMT -4. The time now is 07:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy