LinuxQuestions.org
Register a domain and help support LQ
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, 11: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, 12:03 PM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,491

Rep: Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429
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, 01: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 02:00 PM.
 
Old 08-14-2012, 01:46 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,491

Rep: Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429
that looks something like:
[[ -f <targetfile> ]] || cp <sourcefile> <targetfile>
 
Old 08-14-2012, 06: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, 03:12 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,491

Rep: Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429Reputation: 2429
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:52 PM
Automatically Copying files from the ftp directory into the html directory swatward Linux - General 3 04-17-2005 11:55 PM
Copying all files from subdirectories into one directory Hegemon Linux - General 3 01-17-2005 12:25 PM
Copying linked files, replacing directories in bash scripts? ta0kira Programming 2 10-10-2004 05:46 AM
copying files to protected directory? webazoid Linux - Software 1 07-11-2004 10:08 AM


All times are GMT -5. The time now is 10:39 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration