We help IT Professionals succeed at work.

run cronjob

XK8ER asked
hello there,
I would like to setup a cronjob to run every day every 24 hours but with a twist..
if it possible to run lets say today at 1:00pm then tomorrow at 1:01 then the next day 1:02 etc..
each day and extra minute.. is this possible?
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

this is not possible with cron itself

may I ask why you need such a scheduling?
and also, will it "reset" to 1pm at some time? for example, when it reached 2pm or so?
or once per month reset to 1pm?
please clarify
You could start a shell script at 1pm every day and have the shell script write a log file to a folder.

Then for each log file it finds in the folder do a "sleep 60" command:

#! /bin/sh
for i in /logfolderdirectory
  sleep 60

The shell script could then go on to do whatever task you want it to do.
I should have said - obviously the log files would have to have unique names - something like:
myshellscript > logfile.`date +%y%m%d`
so the logfile's name would have the day's date in yymmdd format appended to it.


I am trying to run a php script.. and for example it takes about 30 seconds to finish running..
so I need to run it exactly 24 hours after finishing.. so if I run it every 24hrs its 30 seconds too early..
You could use the last line in your php script to run the Linux "at" command to run itself in 1 days time:
at now + 1 day -f mycommandfile

(I seem to recall that you can run a Linux command in PHP by putting it in `backticks`?)

I'm not sure if the atq is accurate to more than the nearest minute, so you may have to do a "sleep 60" first to ensure that at least 1 full minute has passed.

That way you don't need cron at all, as each job would queue the next one to start 24 hours later.