Is it possible to have 1 cron job kick off one of 2 other cron jobs for the next day rather than both on a set time?
Is it possible to have 1 cron job kick off one of 2 other cron jobs for the next day rather than both on a set time?
Do you mean that you want a cron job to schedule another cron job?
If that is your question, why not have one script that behaves differently depending on an external variable?
█ Xavier L | Community Public Relations Manager (Free Hosting Support)
█ Yes, my position is too cool to even exist!
█ How am I helping? Rate this post by clicking theicon below! (this is even better than "liking" a post)
█ Terms of Service | Acceptable Use Policy | x10Hosting Wiki
It sounds like you want a different job to run each day, so why don't you have 3 cron jobs and tell them to check what day it is? Maybe you can do something like:
Code:pseudocode // run on odd days if day_of_year % 2 == 1 then execute // run on even days if day_of_year % 2 == 0 then execute
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer
If you want a job to run sporadically, you can use at (the exact syntax of at may depend on the OS flavor, so here's another manpage). If you want it to run periodically, use one of the above solutions.
I have one cron job that does some work on a 1x daily basis.
Approximately once a week, there's updates in needs to run every 10 minutes instead of every 1 day.
I don't want to have a cron job that runs every 10 minutes every day. If there was a way that the daily cron job can kick off the 10 minute cron job on an as-needed basis, that would be ideal.
Is the day these updates need to run dependent on an external condition or is it a predetermined (albeit semiperiodic) time? What's the condition for stopping the scheduled jobs?
If you need to run a few of the 10 minute updates, at might be the simplest way to go.
If you know ahead of time when the updates will run (that is, the time isn't dependent on an external factor), you could write a more complex schedule for the updates cron entry. You might need to write multiple entries. For example,
I believe all modern crons (according to the manpage, absolut runs ISC Cron V4.1; ISC is the newer name for Vixie cron) support lists of ranges and range steps, but I could be wrong.Code:# Run updates every 10 minutes on even hours on the 4th and 18th, # and on odd hours in the morning and evening on the 12th and 26th */10 */2 4,18 * * updates */10 1-7/2,21-23/2 12,26 * * updates
If that won't work, you can:To disable the update script, do basically the same thing but comment out the line for the scheduled update script in step 2. This approach is error prone, which is why a complex schedule is better than updating crontab. If you must use the last approach, add numerous sanity checks: when you schedule the update script, run it only on the current day and have the update script double check that it should run.
- use crontab -l to get your current crontab,
- add (or uncomment & alter) a line for the updates,
- save that to a file $crontab,
- then run crontab $crontab to install the crontab with the update script scheduled.
It sounds to me like maybe you're taking an approach to this that is more difficult than necessary. Maybe you can code your webpage to do the work as necessary.
For example, on my site I need to make sure a directory contains all the images needed to generate some content on the page. If one of the images is bad or missing, I have a script that will re-make them (they're very small images and there's about 70 of them) when a user loads the page. This adds maybe 1 second to the user's load time. So, maybe you can do something like this?
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer