2

I am creating Automated cron tab using php. i need to run this cron tab for following times.

24 hours or 36 hours or 48 hours or 72 hours or 96 hours.

i am confused to setup in cron tab for 36 hours.

How do I set up a cronjob that runs every 36th hours? Please Advise

Padmanathan J
  • 4,614
  • 5
  • 37
  • 75
  • 1
    You'll have to set up multiple jobs for different timespans, all running the same job. There's no way to directly tell cron "every 36 hours", because the hours range in a cron definition is maximum 23 hours. – Marc B Jul 18 '13 at 14:45

3 Answers3

2

I don't think you can specify further than 24 hours.

You could have it run every hour, and each time it hits have it increment a var stored in a database or file, then when that var hits 36 run the script and reset it to 1.

EDIT: on the same note you could have it run every 12 hours and have it increment by 12

for example :

$var = (int) file_get_contents('count.txt'); 
$var++;
if($var === 36) {
   //run script
   //update count.txt
}else {
   //update count.txt
   die(); 
}
JohnnyFaldo
  • 4,121
  • 4
  • 19
  • 29
2

It's not a great solution, but...

Set the cron job up to run the script every 12 hours. In the script, add something like:

$hour_of_year = date('z') * 24 + date('H');

if ($hour_of_year % 36 == 0) {
    // RUN THE PROGRAM

} else {
    // DONT RUN THE PROGRAM
}
Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
2

To schedule a cron job to run every 36 hours just use two strings:

0 0 0,3,6,9,12,15,18,21,24,27,30 * *
0 12 1,4,7,10,13,16,19,22,25,28 * *
Ruslanick
  • 73
  • 7