LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-21-2008, 03:10 AM   #1
MaRock
LQ Newbie
 
Registered: Aug 2008
Posts: 13

Rep: Reputation: 0
Exclamation How to know if a folder is being written with a file at any point of time?


hi all,

how do i find if somefile is being written to a folder at any point in time. i.e in other words , i want to know if a file being written to a folder is done or is still being done.
eg: i copy file 'x' to folder 'Y' now i want to copy x into another folder 'Z' but i want to make sure that 'x' is completely copied to the folder 'Y' before the file is copied from 'Y' to 'Z'. is there a command or code logic which will tell me if the write is done or not?

--Maneesh
 
Old 08-21-2008, 03:17 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
cp x/file y/ && cp x/file z/

Last edited by jschiwal; 08-22-2008 at 01:45 AM.
 
Old 08-21-2008, 03:31 AM   #3
MaRock
LQ Newbie
 
Registered: Aug 2008
Posts: 13

Original Poster
Rep: Reputation: 0
thanks jschiwal

Quote:
Originally Posted by jschiwal View Post
cp x/file y/ && cp x/file y/
will try this out..
thank u
 
Old 08-21-2008, 03:34 AM   #4
MaRock
LQ Newbie
 
Registered: Aug 2008
Posts: 13

Original Poster
Rep: Reputation: 0
can u pl explain

Quote:
Originally Posted by jschiwal View Post
cp x/file y/ && cp x/file y/
hi jschiwal ,

Can u pls explain how this works?
 
Old 08-22-2008, 01:40 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
The "&&" stands for and. If the first command is successful, the next command is run. Otherwise it is skipped.

I meant to write "cp x/file y/ && cp x/file z/". Since the source is the same you don't need to copy from y/. If y/ is a mounted share and you want to move it if someone else (or another process) is finished writing, you could look at the output of lsof and not copy a file if it is listed. You could also use the find command and check if the mtime value is more than a certain amount of time.

One of the fields will indicate the type of access. If the access is "read" than it would be ok to copy it. If the access is write, then you may want to wait.
Code:
lsof | grep pod
amarokapp 16769   jschiwal   20r      REG               0,19 11248947 19111954 /mnt/hpmedia/podcasts/Slashdot Review - SDR News/SDR2008-08-22.mp3 (hpmedia.jesnet:/home/jschiwal/podcasts)
Code:
lsof | grep pod | awk '$4 ~ /r/ {print $9}'
/mnt/hpmedia/podcasts/Slashdot
jschiwal@qosmio:~> lsof | grep pod | awk '$4 ~ /w/ {print $9}'
 
Old 08-22-2008, 02:26 AM   #6
MaRock
LQ Newbie
 
Registered: Aug 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks
this was exactly what i was looking for..
great help
 
Old 08-22-2008, 03:30 AM   #7
MaRock
LQ Newbie
 
Registered: Aug 2008
Posts: 13

Original Poster
Rep: Reputation: 0
jschiwal,
i have one more question...

Now suppose i write a script, now i want it to run at regular intervals (with out scheduling it in crontab) .. in other words i write a daemon / init script.. how do i achieve this?
 
Old 08-25-2008, 01:43 AM   #8
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Cool

Quote:
Originally Posted by MaRock View Post
jschiwal,
i have one more question...

Now suppose i write a script, now i want it to run at regular intervals (with out scheduling it in crontab) .. in other words i write a daemon / init script.. how do i achieve this?


To run a script at regular intervals I believe you will have to use crontab.

Or else you can use run this command in a script say rc.local
Code:
((while true;do date; sleep 10; done;) >> /any/file ) &
This can help you out... it would start running when all of your default scripts would stop executing and would redirect the output in any file in the background.

Hope this helps.
 
Old 08-25-2008, 06:40 AM   #9
MaRock
LQ Newbie
 
Registered: Aug 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks Vikas !
 
  


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
moving a file while is being written omnio Programming 10 03-23-2007 10:25 AM
LXer: This time, it'll be a Wikipedia written by experts LXer Syndicated Linux News 0 07-15-2006 11:54 PM
How can I point a users public_html to a folder on a webserver outside the firewall? Durham Linux - Networking 5 05-13-2006 04:36 AM
Why Do I need to run updatedb each time I search for a file or folder? lennysokol Linux - Software 4 05-30-2005 11:49 PM
How to get last file written to directory kd5giv Linux - Networking 4 03-29-2004 03:26 PM


All times are GMT -5. The time now is 05:59 AM.

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