Run a cron more than once per minute

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;

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)


I am a g33k, Linux blogger, developer, student and Tech Writer for My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.