Sunday, December 09, 2012

Running a Script in a Loop without Cron

There are times when using cron is an over kill for a small task so it makes sense to whip up a small script and use one of the many system commands to repeatedly call it in a loop. BTW, if you have a better way of accomplishing this, I would like you to share it.

That said, here's is an example. I wanted to perform a copy task every 12 minutes whilst working on a sample project. One quick option is to use the watch command - but if you find yourself requiring more cycle then a while loop would also help. But for now, this seems to get the job done. Not the best... hey, but it did  what I required

while [ 1 ]
  cp source dest
  sleep 12
Surprisingly, this worked quite well allowing me to take control of the script an its execution without resorting to the cron system. Nice and handy tip.

Now over to you - how would you run a script every specified minutes without using cron. Please post your thoughts in the comments.

On a totally different topic: I just finished my second Twitter app for another client. That brings together a total of 5 custom apps I've developed for private clients in the last 2 years. 

This last one took me less than a day to finish it. They wanted a specific feature which was the only thing that took me a bit of backwards and forward to finally finish. So, this weekend I did quite a bit more than I wanted, and I'm pleased with myself.

No comments:

Related Posts with Thumbnails