You are here:  » Cron Question...


Cron Question...

Submitted by madstock on Sun, 2006-09-10 22:04 in

For a new site that I have been cobbling together I basically need to schedule a CRON that is different on each day of the week, due to the fact that I have approaching 490 seperate databases that need to be populated (tis a long story!)

Alas my current hosts allow only one Cron per account, and I was wondering if it was possible to add a snippet of php code in a .sh file that does the following:

#!/bin/sh
>>>>> IF DAY IS MONDAY <<<<<<
php /home/path/to/site/001/feeds/downloadscript.php
php /home/path/to/site/001/feeds/gunzipscript.php
php /home/path/to/site/001/scripts/import.php @MODIFIED
php /home/path/to/site/002/feeds/downloadscript.php
php /home/path/to/site/002/feeds/gunzipscript.php
php /home/path/to/site/002/scripts/import.php @MODIFIED
php /home/path/to/site/003/feeds/downloadscript.php
php /home/path/to/site/003/feeds/gunzipscript.php
php /home/path/to/site/003/scripts/import.php @MODIFIED
....etc..
>>>>> ELSE IF DAY IS TUESDAY <<<<<<
php /home/path/to/site/101/feeds/downloadscript.php
php /home/path/to/site/101/feeds/gunzipscript.php
php /home/path/to/site/101/scripts/import.php @MODIFIED
php /home/path/to/site/102/feeds/downloadscript.php
php /home/path/to/site/102/feeds/gunzipscript.php
php /home/path/to/site/102/scripts/import.php @MODIFIED
....etc..

Would some kind soul be able to enlighten me as to what the "IF DAY IS ..." bit of the script would be, please?

Wheras I have access through Putty, I cannot access the Crontab on the sly, not can I run a permanent process (i.e. add a load of pauses).

Submitted by support on Sun, 2006-09-10 23:09

Hi,

Have a go with something like this this:

#!/bin/sh
if date | grep Mon; then
  # do Monday stuff here
fi
if date | grep Tue; then
  # do Tuesday stuff here
fi

Cheers,
David.

Submitted by madstock on Mon, 2006-09-11 09:34

Thanks David, I'll give that a go - would I be correct in assumuing that the following would be correct in terms of "days"

Mon
Tue
Wed
Thu
Fri
Sat
Sun

(Yep, I really did just ask you to confirm that I know the days of the week!)

Furthermore, as I don't need anything to happen on Saturday or Sunday as of yet (although I need to set the .sh file to run every day), what sort of thing would I need to put for those days - can I leave them blank, e.g.:

if date | grep Sat; then
fi
if date | grep Sun; then
fi

or do I need to run some sort of script?

Sorry for the dimness of my questions, I have tried to leave you alone for the past few months.

Submitted by support on Mon, 2006-09-11 10:24

Yes - those are the standard 3-letter day of the week names.

You wouldn't need to do anything for days that you don't want to include. If you only wanted to do stuff on Tuesday and Friday your entire script would be:

#!/bin/sh
if date | grep Tue; then
  #do Tuesday stuff
fi
if date | grep Fri; then
  #do Friday stuff
fi

Cheers,
David.

Submitted by madstock on Tue, 2006-09-12 10:21

Just to say "thanks", that appears to be working okay.