copy file to a directory by sequence


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers copy file to a directory by sequence
# 1  
Old 11-22-2007
copy file to a directory by sequence

Hi

I am new in unix and look for help in urgent.

I have a list of data files that located in a directory, and need to copy to another directory for loading. The condition here is, the list of data files has to be copy over by sequence, and if there is no file in targetted directory already.

Please give me some light.
# 2  
Old 11-22-2007
Code:
cd ${SRCE_DIR}
for FILE in `ls -altr ${SOME_FILEMASK_IF_REQUIRED}` 
do

  if [ ! -f ${DEST_DIR}/${FILE} ]
  then
    echo 'Transferring file: '${FILE}
    cp ${SRC_DIR}/${FILE} ${DEST_DIR}/${FILE}
    echo 'Transfer completed.'
  else
    echo 'The file: '${FILE}' already exists in '${DEST_DIR}'.'
  fi

done

The above was done off the cuff, so you'll just need to check it.

Hope it helps.

Cheers,
Cameron

Last edited by Cameron; 11-22-2007 at 08:47 AM.. Reason: [code][/code] formatting..
# 3  
Old 11-23-2007
Hi Cameron,

Thanks for the prompt reply. The script really help me to get an idea. Smilie
Still have some doubt here.

I have modified the script to as below. I put all the datafile name from the source directory into a file name "mydatafile", in tend to load the datafile by the ordering in the file. The data able to pick up one by one when the destination location has no data, but is not follow the sequence order in the file. How to make it read the file by order?

mydatafile
----------
GGESC00A.2004:01:19:05:00:00.CLIpm
GGESC00A.2004:01:19:05:15:00.CLIpm
GGESC00A.2004:01:19:05:30:00.CLIpm
GGESC00A.2004:01:19:05:45:00.CLIpm


#!/bin/ksh

while [ -f /tmp/hs/source/* ]
do

while read line
do
echo $line

if [ ! -f /tmp/hs/destination/* ] && [ -f /tmp/hs/source/* ]
then

echo 'Transferring file: '$line >> seq_log
mv /tmp/hs/source/$line /tmp/hs/destination/
echo 'Transfer completed.'

else
echo 'File: '$line': loading in progress######'
while [ -f /tmp/hs/destination/* ]
do
echo '**********'
done
sleep 5
if [ ! -f /tmp/hs/destination/* ] && [ ! -f /tmp/hs/source/* ]
then
echo 'File: '$line': loading completed'
fi
fi

done < mydatafile
done
# 4  
Old 11-23-2007
Sadly your script generates nothing my a lot of " ********** ".

Using what I provided before you should be able to :
Code:
#!/bin/ksh

SRCE_DIR=${HOME}/srce
DEST_DIR=${HOME}/dest

cd ${SRCE_DIR}

for FILE in `ls -1A *.CLIpm`
do

  if [ ! -f ${DEST_DIR}/${FILE} ]
  then
    echo 'Transferring file: '${FILE}
    cp "${FILE}" "${DEST_DIR}/${FILE}"
    echo 'Transfer completed.'
  else
    echo 'The file: '${FILE}' already exists in '${DEST_DIR}'.'
  fi

done

SOURCE DIR DETAILS:
[mddev:/home/cameron]
$ ls -al ./srce/
total 96
drwx------ 2 cameron users 8192 Nov 23 23:30 .
drwxr-xr-x 8 cameron 20 8192 Nov 23 23:53 ..
-rw------- 1 cameron users 3 Nov 23 23:17 GGESC00A.2004:01:19:05:00:00.CLIpm
-rw------- 1 cameron users 3 Nov 23 23:17 GGESC00A.2004:01:19:05:15:00.CLIpm
-rw------- 1 cameron users 3 Nov 23 23:17 GGESC00A.2004:01:19:05:30:00.CLIpm
-rw------- 1 cameron users 3 Nov 23 23:17 GGESC00A.2004:01:19:05:45:00.CLIpm

OUTPUT (1st run):
$ tfr2.sh
Transferring file: GGESC00A.2004:01:19:05:00:00.CLIpm
Transfer completed.
Transferring file: GGESC00A.2004:01:19:05:15:00.CLIpm
Transfer completed.
Transferring file: GGESC00A.2004:01:19:05:30:00.CLIpm
Transfer completed.
Transferring file: GGESC00A.2004:01:19:05:45:00.CLIpm
Transfer completed.

OUTPUT (2nd run):
$ tfr2.sh
The file: GGESC00A.2004:01:19:05:00:00.CLIpm already exists in /home/cameron/dest.
The file: GGESC00A.2004:01:19:05:15:00.CLIpm already exists in /home/cameron/dest.
The file: GGESC00A.2004:01:19:05:30:00.CLIpm already exists in /home/cameron/dest.
The file: GGESC00A.2004:01:19:05:45:00.CLIpm already exists in /home/cameron/dest.

Cheers,
Cameron
# 5  
Old 11-24-2007
Many thanks Cameron. Smilie)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

2. Shell Programming and Scripting

Need Help - match file name and copy to Directory

I am trying to sort the following files from folder Bag to Apple, Cat Food, Dog Food. I can get all of the files I want into a new folder, but not sure of the best approch to get them to their final directory My Files ========== apple.1234.ext apple.1235.ext cat food 101.ext Cat Food... (2 Replies)
Discussion started by: mtschroeder
2 Replies

3. Programming

how to copy file to a directory

Hello, I've been spending a lot of hours trying to imitate cp copying a file to a directory. cp I just can't seem to write to a specified directory, it only creates a copy on the current directory. any hints/tips will help! Thanks! here's the code i've been trying to manipulate: ... (1 Reply)
Discussion started by: l flipboi l
1 Replies

4. Shell Programming and Scripting

Copy file after searching in a directory

Hi, I am looking for an answer for following senario: I have a text file (base.txt) which consist list of files to be searched like: base.txt abc.txt def.txt fgh.txt Now i am going to search all the listed files in another directory after reading them one by one, once i found the... (10 Replies)
Discussion started by: apjneeraj
10 Replies

5. UNIX for Dummies Questions & Answers

How to copy a file to a directory?

Hello all, I've been researching this problem for days, and have gotten no luck . =/ How do you copy a file to another directory without being in the same directory as the file? So, for example, say I wanted to copy the file 'my.txt' that is in the directory ' /export/hom0/user/asdf ' to the... (9 Replies)
Discussion started by: kvnqiu
9 Replies

6. Shell Programming and Scripting

find and copy file to another directory..

Hi Everybody, i want a samll help to write a script. i had source location with :/user/bin (bin contains subdirectories with like names emails etc and had several files in each subdirectory) and target location with :/usr/scripts (having same subdirectories names and had some files)... (1 Reply)
Discussion started by: Reddy482
1 Replies

7. Shell Programming and Scripting

Copy the latest file to a directory

Hi Team, I wish to copy the latest file of pattern "MyFile*" to some other location. I need to do all the operation in a single command separated by |. ls -rt <MyFile*> | tail -1 | <copy command>. How can I do? Please help me. Thanks, Kanda (2 Replies)
Discussion started by: spkandy
2 Replies

8. Shell Programming and Scripting

Copy the latest file from one directory to another

Hi All, I am in the directory a/b/processed the files in this directories are -rw-r--r-- 1 owb users 330 Aug 8 chandantest.txt_08082008 -rw-r--r-- 1 owb users 220 Aug 7 chandantest.txt_07082008 -rw-r--r-- 1 owb users 330 Aug 6... (3 Replies)
Discussion started by: chandancsc
3 Replies

9. Shell Programming and Scripting

how to copy a file to a directory ,where file and dir are sent as args to a function?

Hi all, I wanted to know how i can copy a file to a directory and then verify if that file is completely copied or not? Now the issues here is that the dir and the source file are to be sent as arguments to a function( this function should actually copy the files to a dir, then check if its... (0 Replies)
Discussion started by: wrapster
0 Replies

10. Solaris

Copy files from the file to another directory

I have created a file that has list of all the files I want to copy into another directory.Is there a way to do it? Thanks In advance (4 Replies)
Discussion started by: shreethik
4 Replies
Login or Register to Ask a Question