scriptygoddess

14 Jan, 2004

cron jobs

Posted by: Jennifer In: Script snippet

Sometimes the simplest thing are the things that seem the hardest. You're almost embarrassed when you finally figure it out – and realize how simple it was.

Cron jobs. Did you know you can create a script (that could technically be run if you pulled the page up in a browser) – but lets say you wanted to run this script on a regular basis. You can set up a cron job to run this php script.

So below is a screenshot of the "advanced" cron job in cpanel (your implementation may be different, but this will probably at least give you the basic idea).

cronsample.gif

Put your email address in so you'll receive the output (if you have any "feedback" printing to the screen, it will email you this output) for example. Let's say your script is supposed to download a file, and when it completes you have: echo "download was successful!!"; (you'd get an email with that text in it)

In "Command" you put:
php /home/youraccount/PATH/TO/YOUR/FILE.php

the fields for "minute" "hour" "day" etc… that will set up WHEN the script will be run. What you need to put in there so that it's appropriate for your needs (as well as additional information about cron jobs) can be found here:
faq.solutionscripts – crontab
ez-response – how cron works

6 Responses to "cron jobs"

1 | patricia

January 15th, 2004 at 6:10 pm

Avatar

and then there's knowing about it, but having no clue how to implement it. i keep saying that one of these days i'll look into cron jobs, but it just don't make it onto the to-do list.

thanks for the post.

2 | Liam

April 2nd, 2004 at 9:05 am

Avatar

Ok ive tried the cron example above but im trying to use the srcipts in PERL and they aint running, is perl compatible and do i need any special "programs" to get them to work?

3 | Jennifer

April 2nd, 2004 at 9:33 am

Avatar

the example above is specifically for a PHP script to run… I don't think you need to put anything before it to get it to run CGI – does your script run successfully outside of cron? (ie. is is the script or the cron job setup?)

Also just a note (not really related to your quesiton – but to CRON in general) in one case I had trouble with the above for a php script – but it DID work fine if I loaded it up in a browser. I was told to do this instead:

lynx -dump http://www.mydomain.com/cronjobname.php

and that worked… not sure if that's a univeral thing or not (that "lynx" thing…)

4 | brady

August 26th, 2004 at 11:19 pm

Avatar

This is just what I needed. Thanks.

5 | Jennifer

September 7th, 2004 at 9:10 am

Avatar

Another useful page.

which indicated these syntax specifically:
Run once a year: "0 0 1 1 *"
Run once a month: "0 0 1 * *"
Run once a week, "0 0 * * 0"
Run once a day, "0 0 * * *"
Run once an hour, "0 * * * *"

6 | Jennifer

September 7th, 2004 at 9:12 am

Avatar

One more note – to what I had posted awhile ago above about the lynx command… if you need to specify a username/password for the folder/file you're trying to access it would look like this:

lynx -dump http://www.mydomain.com/cronjobname.php -auth=USERNAME:PASSWORD

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements