Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
That will make for an interesting time lapse. Can you post a link when it's done? –  marcusw Dec 16 '09 at 21:03
    
If I make it work, and I remember then yeah. –  Piku Dec 16 '09 at 21:42
add comment

3 Answers 3

up vote 7 down vote accepted

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 :

#!/bin/bash

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

# capture from webcam
/path/to/capture_from_webcam.sh

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.

share|improve this answer
    
That's a nice one :-) What happens if the server is rebooted though? –  ℝaphink Dec 16 '09 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. –  Laurent Parenteau Dec 16 '09 at 23:31
add comment

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

share|improve this answer
    
Cunning, I like that :) –  Piku Dec 16 '09 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 '09 at 21:02
add comment

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 ].

share|improve this answer
    
Hmm need to add modulus for 96 to prevent an overflow. –  Darren Hall Dec 16 '09 at 20:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.