I'm trying to take timelapse images using my webcam. What I want to do is run a script at midnight on 1st Jan, then 00:15 on 2nd Jan, 00:30, 3rd Jan and so on. This can keep running forever, I'll switch it off when I'm done.

I can't do this with Cron, can I, without filling a crontab with every possible combination? I don't know what else to do though.

  • That will make for an interesting time lapse. Can you post a link when it's done?
    – marcusw
    Dec 16, 2009 at 21:03
  • If I make it work, and I remember then yeah.
    – Piku
    Dec 16, 2009 at 21:42

3 Answers 3


Instead of creating a new cron job in your script, and having to remove the "old" cron job every time too, you should use the at command instead. The at command was created exactly for that, to let a command run once at a specific date/time. This way, you won't have to remove the old cron job.

So, you could have your script, lets call it "capture_from_webcam.sh", looking like that :


#schedule next capture for tomorrow + 15 minutes
echo "/path/to/capture_from_webcam.sh" | at tomorrow + 15 minutes

# capture from webcam

And to have if execute for the 1st time, at midnight on January 1st :

echo "/path/to/capture_from_webcam.sh" | at 00:00 01/01/2010

For more information, see the at man page.

  • That's a nice one :-) What happens if the server is rebooted though?
    – raphink
    Dec 16, 2009 at 23:05
  • 1
    @Raphink at jobs are handled by the cron deamon. They are store inside /var/spool/cron/atjobs. So, if nothing purge that directory on reboot, they will still be executed. Dec 16, 2009 at 23:31

You can create a cron job as part of the script you're planning on running. So have the cron job run once, then the bash script creates the next one 15 minutes later and so on.

Here's a previous question that may help: How to create cron job using bash

  • Cunning, I like that :)
    – Piku
    Dec 16, 2009 at 21:00
  • Just be careful to make sure the script deletes the job that has just run, or you'll end up with hundreds of cron jobs which will be run again next year...
    – marcusw
    Dec 16, 2009 at 21:02

You can do this via cron.

You call the same cron script every day at the same time, but you add a sleep statement to the start of the script that sleeps for 15m * date +'%j', this day of the year, [ 001 ... 366 ].

  • Hmm need to add modulus for 96 to prevent an overflow. Dec 16, 2009 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .