Copying one file at a time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copying one file at a time
# 1  
Old 09-02-2008
Copying one file at a time

I am using Korn Shell to process one file at a time. In a recieve directory i have mutiple file but would like to only copy one file at a time. Here i wrote a following code but i am getting find: can not stat error on following line. File exit in the directory. Currently i have 777 privelage to all the directory.

# formulate the source filename, allowing only one file at a time
SOURCE_FILENAME=`find $RECD_DIR/PG*.DAT | awk 'NR == 1 { print $1 }'`

Here is the whole script

#!/bin/ksh
#===========================================================================
# Program......: $XXX_TOP/bin/E_INTCTL
# Date Who Comments SCR #
# --------- ------ ------------------------------------------------- ------
# 28-AUG-08 AA Initial release
#
#
#=============================================================================
PATH=/usr/local/bin:$PATH
. $HOME/.profile >/dev/null
# Define directory shortcuts
INTERFACE_TOP=$XXX_TOP/interface/GL;export INTERFACE_TOP
RECD_DIR=$INTERFACE_TOP/receive;export RECD_DIR
TMP_DIR=$INTERFACE_TOP/temp;export TMP_DIR
REJECTED_DIR=$INTERFACE_TOP/rejected;export REJECTED_DIR
SQL_DIR=$INTERFACE_TOP/sql;export SQL_DIR
DATA_DIR=$INTERFACE_TOP/data;export DATA_DIR
ARCH_DIR=$INTERFACE_TOP/archieve;export ARCH_DIR
LOG_DIR=$INTERFACE_TOP/log;export LOG_DIR

# to start loading copy one file at a time from the $RECD_DIR to $DATA_DIR
# make sure that only data files reside there
echo 'script is starting'
if [ ! -f $TMP_DIR/filelist ]
then
echo 'okay to proceed, no filelist exists'
# create a timestamp
DATE_TIME=`date +\%m\%d\%y_\%H\%M\%S`

# formulate the source filename, allowing only one file at a time
SOURCE_FILENAME=`find $RECD_DIR/PG*.DAT | awk 'NR == 1 { print $1 }'`

# formulate the target filename
TARGET_FILENAME=$DATA_DIR/XXX_INSYNC_GL_GL02_Source.dat

# formulate the archival filename
BACKUP_FILENAME=$ARCH_DIR/XXX_GL02_$DATE_TIME
echo 'Successfully formuate the filename'

# Move the source file into the directory being processed by the UNIX script
# If sucessful, copy the moved file into the archival directory and re-name
#
if [ -s "$SOURCE_FILENAME" ]
then cp $SOURCE_FILENAME $TARGET_FILENAME
chmod 777 $TARGET_FILENAME
# mv $SOURCE_FILENAME $BACKUP_FILENAME
#Copy the file name to newlist
ls $DATA_DIR > $TMP_DIR/newlist
fi
fi
echo 'done script'


Any help is really appreciated.

Last edited by ali_amir24; 09-02-2008 at 02:33 PM..
# 2  
Old 09-03-2008
I figure it out. Find command should be use in this format

SOURCE_FILENAME=`find $RECD_DIR/ -name "PG*.DAT" | awk 'NR == 1 { print $1 }'`

-name was missing from my earlier script. It is working now.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying multiple files and appending time stamp before file extension

Hi, I have multiple files that read: Asa.txt Bad.txt Gnu.txt And I want to rename them using awk to Asa_ddmmyytt.txt and so on ... If there is a single command or more efficient executable please share! Thanks! (4 Replies)
Discussion started by: Jesshelle David
4 Replies

2. Shell Programming and Scripting

How to preserve time stamp while copying a directory from Server B to Server A?

Experts, Please help me out here. How to preserve time stamp while copying a directory from Server B to Server A (3 Replies)
Discussion started by: ahmed.vaghar
3 Replies

3. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

4. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

5. UNIX for Dummies Questions & Answers

Copying files between two time interval

Hi All, I am new to this forum.... Can neone please help me how to copy files between two time intervals i.e. I need to copy files from 6.30 to 9.30 on 5th June 09. Any help is appreciated. (2 Replies)
Discussion started by: Pratik4891
2 Replies

6. UNIX for Dummies Questions & Answers

Copying one file at a time from one directory to another directory.

Hi All i want to write a script which could copy one file at a time from one directory to another directory. Scenerio: Let's say i have 100 file in a dirctory,so i want to copy one file at a time to another directory with a sleep statement in between that of 30 secs. please help me... (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

7. UNIX for Advanced & Expert Users

urgent help needed!!in copying files to /tmp at boot time,pls help!

Hi all, I am trying to boot a an OS from RAM...(its a opensolaris based distro) For this i have picked up 2 key lib files that when copied to /tmp and mounted to respective places will do the job.. The sizes of these files combined comes upto 600mb.(i have 2gb ram) Now i have also located the... (0 Replies)
Discussion started by: wrapster
0 Replies

8. Shell Programming and Scripting

Copying files created after a specified date/time

I need to write a script that copies files from one directory to another that were created after "today 6:30". This script will be NOT be ran at the same time each day. any help is appreciated. (2 Replies)
Discussion started by: jm6601
2 Replies

9. Shell Programming and Scripting

Copying Files in the same order along with time stamps

Hi , I am New to this group and would like to know if someone can help me on this issue : We need to copy some files from a particular directory to another directory in the same order and time stamps .How can this be achieved . For Ex : ./ABC/disk101/XYZ has 1000 files with varying... (2 Replies)
Discussion started by: shyam.appalla
2 Replies

10. UNIX for Dummies Questions & Answers

Copying multiple directories at the same time using Unix

Another Unix question. How would I copy multiple directories at the same time? Right now I do: cp -r -f /directory1/ ../backup/directory1/ I do that for each directory one at a time. But there are multiple directories I'd like to copy. So instead of sitting there and doing one at a time, is... (9 Replies)
Discussion started by: JPigford
9 Replies
Login or Register to Ask a Question