How to know if a folder is being written with a file at any point of time?
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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?
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.