PDA

View Full Version : Time delay for CRON files.



graphicsmanx1
November 5th, 2013, 06:02 PM
Im trying to create a bash script that will execute on some folders and files that are dropped into a shared network folder. I thought about writing some script that will run on X files after X time but I was curious to know if the folders/files dropped to the shared folder change the created date? How can I time the bash script to move the files after an interval of X time to allow full folder transfer across the network?

TheFu
November 5th, 2013, 10:21 PM
Excellent.

Look into stat() and mtime.

I would run the script hourly (use @hourly inside the crontab [man -s 5 crontab for more]), and if the file modification time is less than 2 minutes ago, I would skip that file until the next hour ... assuming it is unmodified at least 2 min when the script runs the following hour.

The amount of time the script takes to run might be important to know too. If this is batch processing long running tasks, then you may want to queue those batch tasks using TaskSpooler.

The ABSG http://www.tldp.org/LDP/abs/html/ might be helpful too.

I hope these leads help someone.

ian-weisser
November 6th, 2013, 12:40 AM
Perhaps the inoticoming package:


Description-en: trigger actions when files hit an incoming directory
inoticoming is a daemon to watch a directory with Linux's inotify
framework and trigger actions once files with specific names are placed
in there.
.
For example it can be used to wait for .changes files uploaded
into a directory and call reprepro to put them into your repository.

Or the gamin package:


Description-en: trigger actions when files hit an incoming directory
inoticoming is a daemon to watch a directory with Linux's inotify
framework and trigger actions once files with specific names are placed
in there.
.
For example it can be used to wait for .changes files uploaded
into a directory and call reprepro to put them into your repository.

The kernel's inotify function tracks changes to the filesystem. You can use it to monitor a folder and watch for changes.
You can find a lot more with the command apt-cache search inotify, including python bindings, command-line bindings, cron-like tools, etc.

graphicsmanx1
November 6th, 2013, 12:55 AM
can you still distinguish between a created time and modified time if you are moving files/folders across a network?

ofnuts
November 6th, 2013, 02:35 AM
There is no "creation time" in unix file systems (some file systems support a "birth time"). The "c" time is a "change" time (any change to the inode (mv/chmod/chown...)), while the "m" time that deals with change to the contents. But oif course if you transfer a file to a new file system, its change time will always be at least as recent as when it appeared on that file system, while the modification time can still be years in the past.