LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   is there a way to check for newly created files without having to access the mount (https://www.linuxquestions.org/questions/linux-general-1/is-there-a-way-to-check-for-newly-created-files-without-having-to-access-the-mount-625821/)

ignarus 03-05-2008 03:04 AM

is there a way to check for newly created files without having to access the mount
 
I'm looking for a way to know if files were created on a mounted usb drive without having to access the drive. The reason is that I have written a script which needs to check for the existence of a certain file periodically. However if I use an ls or find, the drive will never go into sleep state any more.

Is there some way to get this information without disturbing the disk?


Thanks

Poetics 03-05-2008 03:09 AM

If something's writing to the disk, as in creating a particular file, it wouldn't be sleeping anyway ... ;)

You could just ls or cat the file list in long intervals, and run your checks against that, but something tells me you're looking for something both a) easier and b) much harder to implement.

What is the type of file being looked for; e.g. is it automatically generated by a script or other action, does it happen on a schedule, is it something you would have put on there when you loaded the disk, et cetera?

ignarus 03-05-2008 03:50 AM

The script automatically mounts and unmounts usb disks when they are plugged/unplugged on my linux server machine based on the unique id of the disk and runs at 5 second intervals. I enables me to plug/unplug the devices without having to log on to the system and mount/umount them manually. Because of the caching there is the possibility of data loss when the drive is unplugged without a prior umount so I let the script check for a file called @eject in the root of the disk. If it exists the script will unmount the disk properly.

As you can see this file can be created at any time by a user e.g. via samba. So for example I have a WD500 connected which start sleeping after 15 min of no activity and normally it would be sleeping until somebody accesses it through samba. With the current script however it will never go to sleep. I am aware of the sync and dirsync options for mount to disable caching but I would want to avoid using them. Ideal would be if there was some way for the script to check if there has been some write operation for the disk but I don't know if this info is kept somewhere by the OS.

ignarus 03-05-2008 04:01 AM

ok I think I posted too quickly :). The last modified date of the mount point seems to be updated when a write operation is performed on the disk. This way I don't need to go into the moint point to know if there has been a write operation.
Thanks anyway for the reply!


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