Cron Jobs?

software development

#1

Is there a good guide that shows how to setup a cron job on dreamhost to run a php file at a certain time everyday?

Thanks in advance for the help!!

-Rob

Apartments for Rent and Roommates | National Parks and Camping Reviews | NCSU Apartments


#2

Basic format:

          • bash /home/USERNAME/file.blah

The asterisks are:
Minute (0-56)
Hour (0-23)
Day of Month (1-31)
Month (1-12 or name (e.g. “May”))
Day of Week (0-6, zero being sunday, also can write “sun” for sunday etc.)

For instance:

15 5 * * * bash /home/USERNAME/myheadin.sh

Will “bash myheadin.sh” at 5:15am every day (* is a wildcard).

Though, to answer your question, I’d bet there is a good guide out there somewhere.

Note: For php files, just replace bash with php in the example.
Also note: After the time entries you do NOT need the username on DH (compared to if you were using your own linux box).

Check out Gordaen’s Knowledge, the blog, and the MR2 page.


#3

Good deal – I want to schedule “rake clear_logs” as a cron job. Do I need to wrap this in a shell script?


#4

No, you should be able to run straight commands just fine with Cron. You can also add

MAILTO=youremail@wherever.com

to the crontab so that it will e-mail the output of each job to you. That’s especially useful when you are first testing Cron jobs. Just be sure to use full directories or variables for the paths. You could add it to a .sh if you wanted to add some extra output text or information for your own benefit.

Check out Gordaen’s Knowledge, the blog, and the MR2 page.


#5

Good deal – thanks!