Page 1 of 1

Working with Cron?

Posted: Wed Aug 13, 2003 2:49 am
by Caped Knight
I have a website in which I need to update the database once every hour. I only have an obscure idea of how. Can someone point me to a tutorial or something? I'm not very good with Unix. I just need to run once script every hour.

Thanks.

Posted: Wed Aug 13, 2003 2:54 am
by qartis
Add this to your crontab:

Code: Select all

01 * * * * /path/to/php /path/to/a/php/file/which/updates/your/database.php
EDIT: Too many stars :oops:

Posted: Wed Aug 13, 2003 2:56 am
by Caped Knight
Thanks, qartis. Can you tell me what it all means? Just so I understand in case I'm using different timing in the future.

Posted: Wed Aug 13, 2003 3:00 am
by qartis
Whoops, I read "not very good" as "very good" :)

To edit your crontab, at a sh or bash prompt, type 'crontab -e' to edit your crontab, and then add that line into it. Then press the [ESC] key, and type "ZZ" [Enter] to save your crontab and quit vi.

Posted: Wed Aug 13, 2003 3:01 am
by Caped Knight
Lol. Thanks again.

Posted: Wed Aug 13, 2003 3:06 am
by qartis
Oh, and the meanings? Well, a crontab uses a simple structure. The 01 * * * * represents this:

A minute, expressed as a number from 0 through 59.
An hour, expressed as a number from 0 through 23.
A day of the month, expressed as a number from 1 through 31.
A month of the year, expressed as a number from 1 through 12.
A day of the week, expressed as a number from 0 through 6 (with 0 standing for Sunday).

And an asterisk means every one. So, 01 * * * * means "every month, every day of the week, every hour, one minute out of the hour (the first one).

To get a cron job to run at 3:30 PM every day, you would use 30 15 * * *.

Argument number six is the command to run, and everything after it (including spaces) is included in the command.

My first snippet (condensed) would run `/path/to/php /path/to/file/php` as if it were typed at a prompt.