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
sadc(8) 						    BSD System Manager's Manual 						   sadc(8)

NAME
sadc -- system activity data collector SYNOPSIS
/usr/lib/sa/sadc [-m mode] [t n] [ofile] DESCRIPTION
The sadc tool is used to collect cumulative system activity data. The sample system data is collected at intervals t seconds apart, in a loop n times. The binary sample data is written to ofile if specified. Otherwise, the binary data is written to stdout. If the ofile file does not exist, it is created, otherwise it is truncated. sadc is intended to be used as the engine behind the sar(1) command, and is not typically invoked on the command line. Two shell scripts, sa1 and sa2, are provided to drive the typical sampling, saving, and reporting process. OPTIONS
The following options modify the way data is collected by sadc. -m mode Modify the collection of system statistics as specified by mode. Currently only one mode is supported. PPP By default, the collection of ppp network interface statistics is turned off. This is because the number of ppp connec- tions can be very high, causing the raw data file to grow unexpectedly large, especially when samples are collected at short intervals. Use the PPP mode to turn the collection back on. EXAMPLES
/usr/lib/sa/sadc 15 20 /tmp/sample.out This call collects 20 samples at 15 second intervals. The binary data is written to the /tmp/sample.out file FILES
/var/log/sa/sadd Default daily activity file that holds the binary sampling data. dd are digits that represent the day of the month. /usr/lib/sa/sa1 Shell script used to drive the sar data collection. /usr/lib/sa/sa2 Shell script used to drive the sar data reporting. SEE ALSO
fs_usage(1), netstat(1), sar(1), sc_usage(1), top(1), vm_stat(1), iostat(8), sa1(8), sa2(8) Mac OS X Jul 25 2003 Mac OS X
All times are GMT -4. The time now is 06:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy