Feb 112010
 

Since a cron job lists the timeframe in which a task will run incrementally using the minute, hour, day, month and day of the week settings, it seems difficult to process a task more than once a minute.

This can be overcome by using a simple shell script that repeatedly runs the task, with a sleep command between each call to the job. Lets say for some reason you want to clear the mail queue every 30 seconds;


#!/bin/sh
for i in `exim -bpr|awk {'print $3'}`;do /usr/sbin/exim -v -Mrm $i;done
sleep 30
for i in `exim -bpr|awk {'print $3'}`;do /usr/sbin/exim -v -Mrm $i;done
sleep 30

This will run the task two times over the course of a minute (not allowing for processing time). you will then create a cron entry to call the above script, with the minute interval set to “every minute” (*/1).

(btw, this would not be a good idea in case you were thinking “Oh WOW, I can so use this…”)

This will allow the command to run every 30 seconds as opposed to one minute. You can use your imagination here to setup a cron executing a script that runs more than once per minute.

An example off the top of my head would be to take a snapshot via a webcam every 10 seconds to do time lapse photography (not that you would want to use a webcam for photography… just an example)

 Posted by at 3:46 pm

 Leave a Reply