LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-08-2012, 10:19 AM   #1
dsfreddie
LQ Newbie
 
Registered: Jun 2012
Posts: 11

Rep: Reputation: Disabled
Help with Logic - Copying the same files by 2 Linux scripts to same directory


Hi All,

Good Morning !

Can anyone help me understand the following scenario.

Scenario 1 : 2 LINUX Scripts(Process 1 & 2) are trying to copy the same file (lets call it FileA.txt) to the same directory (lets say, /home/abc/zyz) at the same time. If both copy is happening at the same time, will the 2 LINUX Scripts abort ?

Scenario 2 : Process 1 copied the fileA.txt to the directory & this file is being read by another script. Process 2 tries to copy the file again while it is being read by Process 1.

What will happen in these 2 scenarios ?

Thanks Much for your inputs,
Freddie
 
Old 08-08-2012, 11:03 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
1. the last (finished) copy will win, the result will be available.
2. process 1 will have access to the first copy as long as it keeps the file opened, but the file will be lost afterward. Process 2 will create a new copy.

see inodes for better understanding: http://en.wikipedia.org/wiki/Inode
 
Old 08-13-2012, 12:53 PM   #3
dsfreddie
LQ Newbie
 
Registered: Jun 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.

Is there a way to put a validation in the linux script which will do the following,

Quote:
find $sourcepath/*datevalue_filename* -type f -newer /tmp/start -not -newer /tmp/end > $destinationpath/wcc_cpmg_nt_bus_gs.txt
In the below FOR Loop, is there a way to put a logic to check whether the file *datevalue_filename* already exists in the destinationpath.

Quote:
for name in `cat $destinationpath/wcc_cpmg_nt_bus_gs.txt`
do
cp $name $COMMON_INBOX
echo $name;
done
If the date_filename is available, we shouldnt copy the file again.

Thanks Much,
Freddie

Last edited by dsfreddie; 08-13-2012 at 01:00 PM.
 
Old 08-14-2012, 12:46 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
that looks something like:
[[ -f <targetfile> ]] || cp <sourcefile> <targetfile>
 
Old 08-14-2012, 05:04 PM   #5
dsfreddie
LQ Newbie
 
Registered: Jun 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
Hi Pan, Thanks for your reply.

Can you pls let me know what does the below code do ? Can i put this in the below FOR loop ?

Quote:
for name in `cat $destinationpath/wcc_cpmg_nt_bus_gs.txt`
do
cp $name $COMMON_INBOX
echo $name;
done
Thanks
Freddie
 
Old 08-15-2012, 02:12 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Hm, I do not really understand what do you want to do, would be better to write an example. This small piece of code will copy the files listed in wcc_cpmg_nt_bus_gs.txt into $COMMON_INBOX.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copying files from cdrom to directory dricharde Linux - Software 3 12-05-2006 11:52 AM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 10:55 PM
Copying all files from subdirectories into one directory Hegemon Linux - General 3 01-17-2005 11:25 AM
Copying linked files, replacing directories in bash scripts? ta0kira Programming 2 10-10-2004 04:46 AM
copying files to protected directory? webazoid Linux - Software 1 07-11-2004 09:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration