Make cron “random”

cron

Maybe I'm completely nuts, and if so – that's fine. But how would I schedule a job to on-some-random-schedule broadcast a goofy message, like from fortune?

clarification
yes – this is my personal workstation – not planning to do something wonky on a production server 🙂

Best Answer

at has a simpler interface for this type of purpose if at is installed, the machine is running atd and the user is allowed to use the command.

For example (check the exact syntax using man at or info at),

at -f file now + 53 minutes

or

at -f file now + 2 hours

will run the commands in the specified file in 53 minutes or 2 hours, respectively.

at can then be re-run at the start of the scheduled job with suitable (random or otherwise) start, count, and time-units.

Edit

As Arjan points out helpfully below, if you are using this for other than a toy application you need to think about issues such as what happens

  1. if the next run starts before the previous one finishes (e.g. is the script re-entrant?) or

  2. if a run fails to complete correctly or

  3. if the next run fails to start at all or on time (e.g. what happens if the machine is off when the next run is due to start) and

  4. about the logging and reporting of failed or successful runs.

Related Question