Steve
Steve

Reputation: 1402

Can cron time be altered on the fly?

I have a site that monitors the level of a local creek and alerts the community when a road is about to flood.

99% of the year, polling the creek height every 5 minutes is good enough. Then, like last night, it floods, this time really fast, rising 1m in 30 minutes.

Given that I can detect the rate at which the creek is rising, is there any way to re-write my cron job on the fly so that if the creek is above a certain height, run the cron every 1 minute? Then it reverts back to every 5 minutes when the creek drops.

Upvotes: 1

Views: 190

Answers (1)

klutt
klutt

Reputation: 31409

One way of solving it is to run the job every minute, but configure the job so that itself only does something every five minutes.

If you, however, really want to change the timing for the cronjob, that's of course also possible. I assume from your start that you know how to (otherwise google it, it's easy (both googling and creating a cronjob)) create a cron job, so basically all you need is to create a new cron table and load it in.

I would recommend the first method. It's simpler and keeps things local without possibility to screw up other cron jobs if you make a mistake.

Upvotes: 3

Related Questions