Continuous Copying from a directory to another.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Continuous Copying from a directory to another.
# 1  
Old 11-07-2017
Continuous Copying from a directory to another.

Hello Folks,

Looking for a script, where i can check for the existing of the files in a directory and copying to another.
How can i achieve it in loop for over period of time.

whatever files comes into the folder copied in another without duplicate and should be continuous loop.


Regards,
Sadique
# 2  
Old 11-07-2017
Dear sadique.manzar,

I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.


Kind regards,
Robin
# 3  
Old 11-07-2017
hereis what i am trying:

Code:
#!/bin/sh
DATE=`date +"%d-%m-%Y %H:%M:%S"`
path=/xyz/S1
while true
do
	for  files in `printf "%s\n" $path/*.RTM 
	do
		if [[ -f $files ]] && [[ -s $files ]]
		then
			cp -n $files  /xxx
		else
			echo "file doesn't exist" >/dev/null
		fi	
	done
done

This User Gave Thanks to sadique.manzar For This Post:
# 4  
Old 11-07-2017
The main things to consider are:

What about files that get modified? Do you want to copy them too? Or do files in this directory never get modified?

What about files that are still being written to/created? Do you want to copy these incomplete files regardless?

What lag in the copying can you tolerate? If a cron job ran every 5 minutes would that suffice? If you are trying to mirror in real-time then some mirroring suite would probably do the job better.
# 5  
Old 11-07-2017
Dear Hicksd8,

First of all nice question.
  • What about files that get modified? Do you want to copy them too? Or do files in this directory never get modified?
    Never get modified, its like fly here and then from here to different server.
    .
  • What about files that are still being written to/created? Do you want to copy these incomplete files regardless?
    While incomplete the extension name is .temp, so my script is simply ruling them out.
    .
  • What lag in the copying can you tolerate? If a cron job ran every 5 minutes would that suffice? If you are trying to mirror in real-time then some mirroring suite would probably do the job better.
    As I said, files fly from this server to other. so running every 5 mins may miss files.



Regards,
Sadique

Last edited by rbatte1; 11-07-2017 at 11:06 AM.. Reason: Clearer formatting of response to questions
# 6  
Old 11-07-2017
This could prove quite difficult if the length of time between the file being a .temp and being moved out is just a few seconds.

Do you have any access to the script(s) which is either creating the files or moving the files? It might be easier to rename the files from .temp to .temp2 and you copy all .temp2 files, then rename them suitable for the move script. Can you get into the overall chain of the process?

I'm scratching my head as to how you can guarantee catching all files if they only exist for a second or two. It would only take your script not to be scheduled (due to CPU load or whatever) for a few seconds in order to miss files going through.
# 7  
Old 11-07-2017
Would iWatch be a possible help here? I think you can defined directories to watch and can take action when a file is updated.

The question is also 'What removes the files?' You may still miss files if you don't get to them before the delete happens. How much slack are we thinking? If this is (and I'm just guessing) an FTP server that people deliver to and there is another server that polls it to collect and remove files then there will be a race to get to the file, which is never a good position to be in.

Perhaps your process could be adjusted so that there is an in-bound directory for clients to create files and an out-bound for something to poll and remove the files (presumably after reading them) If you can separate these and have your code do the move after it has done the action you want, this might give you a working solution.

How time critical is the movement of files? If you are trading shares or processing payments then maybe your process could copy the file to the out-bound directory and clean up the in-bound file when it has done what extra you need.


Can you elaborate on what is going on?



Thanks, in advance,
Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying files to a directory

Hi, I am newbie to unix scripting, need a help in the doubt i have. It is " when files are copied to a directory using cp command, they are arranged by default according to the file name, is there anyway where the files that are copied be arranged with respect to their size, with using the sort... (5 Replies)
Discussion started by: pundalik
5 Replies

2. Shell Programming and Scripting

Copying subdirectories of a directory to some other directory and renaming them

Hi, I am a newbie in shell scripting. I have to copy a particular sub-directory (data) from a large no. of directories (all in the same folder) and paste them to another directory ( /home/hubble/data ) and then rename all the subdirectories (data) as the name of its parent directory. please... (8 Replies)
Discussion started by: sholay
8 Replies

3. Shell Programming and Scripting

Copying files to a directory

Hi I have a few questions. I am trying to copy a file to a directory. I need to copy files that do not end in numbers, for example, into a directory. This is what I tried so far. cp filename directorytowhereIwannacopy but it says it can't copy to a directory. I need to copy many files into one... (2 Replies)
Discussion started by: #moveon
2 Replies

4. Shell Programming and Scripting

Copying files from one directory into another.

Could someone please tell me if there is a command similar to head or tail that can be used on directories. I want to select a given number of files from a directory and copy them into another directory. But I found out I can't use head as it doesn't (or I don't know how yet!) work on directories.... (4 Replies)
Discussion started by: Krush187
4 Replies

5. Shell Programming and Scripting

Copying curent directory

I am trying to write a script that first copies all the directories and files from the current directory into a new Directory. I get and error "Cannot copy directory into itself". That's fine. I don't want it to. What I am worried about is when I give this script to my company (they are using a... (2 Replies)
Discussion started by: Fred Goldman
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 Dummies Questions & Answers

Copying files from one directory to Other

Hi UNIX Gurus, Could please help me out regarding following situation. I am copying some files from one directory to other directotry using following command. cp /var/tmp/*date*.gz /var/tmp/user/ Problem: Once the copy has completed, I need to check whether all the files (including... (3 Replies)
Discussion started by: satishkeshetty
3 Replies

8. UNIX for Dummies Questions & Answers

Copying with directory structure

Hi, I need to copy a set of directories along with all sub directories and files from one unix box to another. Any ideas? cnfsed (4 Replies)
Discussion started by: Cnfsed
4 Replies

9. UNIX for Dummies Questions & Answers

copying a file from one directory to another

Hi This is my first day in Unix, and I am trying to copy a file called holiday.txt from my D drive into the C drive folder called h like currently i am in D drive, i want to copy my holiday.txt into C\h (C drive, h folder) i am able to copy the file in the same drive, but how to do the... (5 Replies)
Discussion started by: soujanya_srk
5 Replies

10. UNIX for Dummies Questions & Answers

Problems with Copying Directory

Hi, i'm completely new to Unix. I'm trying to copy my "Pictures" folder, and all the folders under it, to a different folder "Photos". So say "Pictures" has a sub folder "2". what happens is "2" is copied to "Photos" like i want it to, but then a sub directory "tmp2" is made which... (3 Replies)
Discussion started by: brudnerx
3 Replies
Login or Register to Ask a Question