Cygwin Cron 'Seconds' Patch v1.0 by Kevin O'Mara (kjomara@scienceus.org) Project Completed on: 05/05/2012 Project Page: http://www.sandbars.org/cronSecondsPatch INTRODUCTION: Sometimes, one will need the functionality of cron, but need it to function within a time base of seconds. The standard Vixie Cron does not provide this functionality, mainly because of its chosen crontab interface. It just isn't possible to set the process execution time in seconds, simply because the interface makes it illogical, and because seconds functionality isn't built into the source. Whether this is by design, or simply a consequence of the chosen interface format, is a topic left open for discussion. Regardless, this patch changes all of that. It provides cron functionality in matters of seconds ONLY. This means that the cron revision provided by this patch is only good for firing off ONE task consistently within 2 to 59 seconds. Functionality for minutes, hours, and so forth have been stripped out of this implementation out of necessity. If you need the official, original funcionality of cron, you will have to forget this patched version and continue using the original, standard, unpatched implementation. Even though, it IS possible to get both this patched revision, and the official, standard version installed and running side-by-side happily - just don't get confused during the process. Instructions for doing this are not provided here. The crontab will only allow for ONE entry in this revision, not multiple entries. I have found the code for cron to be quite confusing in this regard (for multiple entries), since it is based upon a minimum granularity of minutes, not seconds. Due to the fact that the job entries structures do not contain any process identifying information, such as a process ID, it is difficult, or almost impossible, to distinguish between them as they need to be run using the codebase as it is implemented. Hopefully, I'll get it figured out sometime. Until then, only ONE entry in the crontab is allowed. I'm sure you can still figure out how to run multiple processes in various seconds increments with one process, even with this limitation, if such is needed. The man pages have NOT been patched, so they will not reflect the functionality of this patched cron. NEW CRONTAB FORMAT: The format of the crontab for this patched version is as follows: "[(2-59) seconds] [process]" NOTE: Do not include any quotes, braces, or parentheses in the actual crontab, for these are provided in the example only for aesthetic reasons. Also, do not include the words "seconds" or "process" in the crontab. No number of seconds less than two, or greater than fifty-nine will be accepted. This patched version of cron will not handle empty crontabs gracefully. This patched cron will crash if an empty crontab is encountered. Thus, even though 'crontab -e' will validate empty crontabs, they do not serve as valid for this patched cron version. This will hopefully be fixed in a later version of this patch. EXAMPLE CRONTAB: The following single line added to the crontab will execute the script 'twenty.bash' located in the '/home/user/' directory every twenty seconds: "20 /home/user/twenty.bash" DO NOT INCLUDE QUOTES IN THE CRONTAB. Again, these are provided only for aesthetic reasons. If you need to execute a windows binary, read up on using cygwin using the '/cygdrive' directory. I'll give you a starting point. If you need to access a directory on the C: drive, specify '/cygdrive/c' as the root directory. ADDITIONAL CRONTAB NOTES: Contrary to intuition, the asterisk (*) will not function AT ALL in the seconds position whatsoever, as it would for other time considerations in the standard implementation of cron. Always use the provided, re-built crontab command that comes with this patch codebase to install your crontab file, or else you might run into problems. It provides error checking relevant to this cron patch revision. The command `crontab -e` should be run to modify the crontab in ALL situations. Again, IF YOU NEED TO MODIFY THE CRONTAB, USE NO OTHER METHOD THAN 'crontab -e'. ADDITIONAL GENERAL NOTES: As stated before, this patch was produced from the Cygwin-provided source of `cron-4.1-59`, which is Vixie Cron. It has not been tested under any other platforms at this time, but I imagine that the patch will integrate, compile, and work, regardless. INSTALLATION: Download and install the latest 'cron' and 'cygrunsrv' from Cygwin's 'setup.exe' so that all of the standard tools related to cron will be available, such as 'cron-config'. Then, install the cron source from Cygwin's 'setup.exe' so that you have the source code from which to apply this patch. The source will be installed to the '/usr/src/cron-X.X-XX' directory. Copy the patch into the source directory (/usr/src/cron-X.X-XX): "cp cronSecondsPatch.v1.0-CYGWIN-4.1-59.patch /usr/src/cron-X.X-XX" (where cron-X.X-XX is the current version of cron. Normally, I would just write 'cron-4.1-59' instead of 'cron-X.X-XX', but I am accounting for future versions of cron that should still work unmodified with this version of the patch.) and then, run the following series of commands: "patch -p1 < cronSecondsPatch.v1.0-CYGWIN-4.1-59.patch" "make" "make install" And then, use the provided Cygwin `cron-config` installation tool to install the patched cron as a Windows service. That's it. It's that simple. CREDITS: Thanks to the hard work of the original developer(s) for making something like this a reality under Windows (and eventually all platforms) at no cost. Cron is the most reliable, time-tested tool of this type. Hopefully, you will find that this unofficial patch does not taint cron's long-standing reputation as such. DISCLAIMER: You choose to use this modification AT YOUR OWN RISK. It has not been certified for production environments. If any loss of data, hardware, your precious time, or any other asset has been experienced, the author does not claim ANY responsibility. ALWAYS use caution and common sense. Review, test, and learn from the patched application before using it. AGAIN - DO NOT COME CRYING TO ME IF ANYTHING GOES WRONG (however, I always appreciate constructive feedback). Hope this helps. I know it fills a niche, since there is no other process time-scheduling solution that exists that includes seconds functionality that will successfully run as a service under Windows 7 (that doesn't cost mucho bucks, anyway). Again, This patch was produced out of a consideration for a personal need for such. Again, I hope you find it as useful of a solution as I have. FIN: TTFN.
Download my latest Cron 'Seconds' Patch here: cronSecondsPatch.v1.0-CYGWIN-4.1-59.rar.
The password for this archive is: sandbars.org-kjomara@scienceus.org.
I hope that you find this patch useful. Please reply with any constructive feedback or comments you may have.