Home » Questions » Computers [ Ask a new question ]

Run Linux script at time 'n' on first day, 'n+15 mins' next day, and so on

Run Linux script at time 'n' on first day, 'n+15 mins' next day, and so on

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.

Asked by: Guest | Views: 407
Total answers/comments: 2
Guest [Entry]

"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."
Guest [Entry]

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