World class hosting that doesn’t suck. Use coupon code UPSTARTBLOGGER for 3 free months.

It doesn’t matter what software you’re using to power your blog or Web site—WordPress, Textpattern, Drupal, Pligg, etc. At some point, there’s a good chance you’ll need to run cron jobs to automatically execute various tasks on your preset schedules.

For example, it’s a very good idea to schedule automatic backups of your database. Your site may also require the regular, automatic execution of a script to update data (for example, if you use the RSS Importer with Pligg, you’ll want to automatically update your feeds). I’ll show you how to do both.

There are two ways to set a cron job, one esoteric (using Unix commands), and one easy (using cPanel, or some other graphical interface). Even cPanel can be tricky (I had help from the excellent support at AN Hosting to get my own cron jobs working).

Here are some tips designed for beginners.

Getting Started

This tutorial assumes you’re using cPanel, one of the most popular hosting control panels. If you’re on a shared hosting plan, there’s a good chance your host uses cPanel (some popular hosts, like DreamHost and GoDaddy, don’t). But even if you don’t have cPanel, your control panel will probably let you create cron jobs without knowing Unix, in a way similar to what I’ll describe below.

Note:If you’re looking for a host, it’s a good idea to find one that uses cPanel; once you become familiar with it, it’s easier to change hosts if you find out yours sucks and you have to move to another one (be sure to read How to Find a Web Host That Doesn’t Suck).

Let’s get started. Log in to your cPanel and look for the Cron Jobs icon:

cPanel Cron Jobs

Click on the image and you’ll be asked to choose your experience level. If you’re reading this, you want to click on Standard.

Creating a Cron Job

Now that you’re at the Standard Cron Manager, let’s create a cron job. You can set a job to run at a specific interval or at a specific times. Creating a cron job requires only three simple steps (see picture below):

Cron job

  1. Enter your email address where it says: Please enter an email address where the cron output will be sent. Cron will send you a message when the job is executed, so you’ll know if there are any errors.
  2. In the Command to run: field, enter the full path to your script (you may need to check with your host for this).

    If you want to run a php file, the command will begin with php. For example, if you want to run RSS Import to update your Pligg feeds, you’d enter php and the path to your import_feeds.php file.

    On AN Hosting, your path would look something like this:

    php /home/[your username]/public_html/rss/import_feeds.php.

    If you want to run the automatic backup script, which backs up your MySQL database and emails a copy to you (see 8 MySQL Backup Strategies for WordPress Bloggers (And Others), strategy #7), you’d enter /bin/sh (since this is a shell script), and the path to your script.

    On AN Hosting, your path would look something like this:

    /bin/sh /home/[your username]/etc/upstart_cron_backup.sh

  3. Now you need to set the schedule.
    • Set the Minute(s). You can set a short interval here, or minutes of the hour (you can select multiple items in this—and the other— boxes by using the Shift and Command keys). If you don’t care about minutes, leave this set to 0).

      If you want to test things, set this to run Every Five Minutes. This is a good interval for running the script, checking your email for errors, and changing settings before your inbox gets inundated with cron messages.

    • Set the Hour(s). If you’re creating a cron job to run RSS Import, you might want to set this to Every Hour. If you’re setting up a backup script, you might choose an hour in the middle of the night for nightly backups.
    • Set the Day(s). You’ll probably want to leave this set to Every Day, but you can also choose specific days of the month.
    • Set the Weekday(s).
    • Set the Month(s).

When you’ve set the schedule, your cron job is done. Click the Save Crontab button. If you set it to a short interval for testing, you should have an email with your output within a few minutes. If there’s an error (usually a problem with your path), check your settings.

Comments
  1. links for 2007-08-06 added this trackback on 06 Aug 07

    [...] How to Create a Cron Job in cPanel (tags: cronjob cpanel cron) [...]

  1. Patrix added these pithy words on 26 Mar 07

    Any idea how to write a cron command for counting and listing unique outbound links every week/month? Just wanted to see how many unique sites I link to? Or if I am linking to some sites more than others?

  2. Robert Ellis added these pithy words on 26 Mar 07

    Sorry, Patrix, I have no idea. But you might try this: SEO Tools » Outbound Links Check.

  3. reneesh t k added these pithy words on 16 Apr 07

    Hi,
    Can we change the cron time of cpanel using php program?
    I want to change the time of execution of cron job using php program means the admin of the website want to edit the time of cron job within the admin page of the site. Is it possible.?. He dont want to edit the cpanel.

    Can you help me.

  4. Robert Ellis added these pithy words on 16 Apr 07

    I’m not sure I understand what you mean. But if you want to run a cron job from WordPress, instead of using cPanel, it’s possible with a plugin. You can try WP-Cron.

  5. pratik added these pithy words on 26 May 07

    Hi Robert Ellis,
    I am very thankful to you because of getting help from you. I am not added cron-jobs yet. but I will put in my site in 2 days.but it will be very useful for me that I think…

    Have you any more idea about creating cron-job. Using Unix-commands?

  6. Robert Ellis added these pithy words on 26 May 07

    pratik, you’re very welcome.

    As far as using Unix to create cron jobs, I’m not likely to write about something like that, but here’s an article that might help: Newbie: Intro to cron.

  7. pratik added these pithy words on 28 May 07

    Hi Robert Ellis,
    I tried that technique. But I think I was wrong in someway.. because when I try to save cronjob, it will do nothing for me. when I am going to again in cronjob in cpanel saved information is lost…

    I put the mail address in first top box. And then commant to run. I put my files address
    like “php /home/username/public_html/cronfile.php”;

    and selected time is every 5 min. all other I put blank.. and also I tried it for default..

    have you any idea about this?

  8. Robert Ellis added these pithy words on 28 May 07

    pratik, most likely the problem is with your path. This can vary depending on your host, so the best thing to do is contact support for your hosting company and confirm that you have the right path.

    Also, I’m not sure what you mean by “all other I put blank”. You should select “Every…” in the other time fields. Every hour, every day, etc. You should get an email with any errors.

    Good luck!

  9. BV added these pithy words on 10 Jun 07

    If I want to setup 20 Cron jobs, it seems like I need to do this 20 times. Is there an easier way to setup multiple cron jobs at one go?

    thanks

  10. Robert Ellis added these pithy words on 10 Jun 07

    BV, if you want to set up 20 Cron jobs, you’d have to follow these instructions 20 times or manually edit a crontab file. You’ll need to ask tech support for your host to do this.

  11. Contrid added these pithy words on 10 Jun 07

    Thank you very much!
    This is a great cronjob article!

  12. BV added these pithy words on 10 Jun 07

    Thanks Rob – good article.
    I wish I could have read this article when I started off with cron jobs… this article makes this easy.

    cPanel should make things easier based on this discussion!! :-)

    Cheers
    BV

  13. Abhishek added these pithy words on 21 Jun 07

    Hello All,
    I have this cronjob which is set to run every 10 minutes. It simply executes on php file. But execution takes more than 10 minutes..lets say 12 minutes. So in this case I am not getting any email for completion of cron job. So does that mean cron jobs are not running at all ??

    please help me in this,

    Thanks,
    Abhishek
    http://www.digi-corp.com

  14. Robert Ellis added these pithy words on 21 Jun 07

    Abhishek, even if the cron job takes longer to execute than the interval you have set for it to execute, it should still work if things are properly configured. I’d get in touch with support for your host and see if they can help you troubleshoot.

  15. Amit Pathak added these pithy words on 11 Jul 07

    Hello Sir,
    I want to setup cron job after 3 day one mail will be sent to the user then mail file is in php file and if we did not get response from the user then again after 14 day again another mail will be sent and if we got respose then there is no need to send another mail days will be counted from the day when he/she enter our request form pls help me i am new on this cron tab setting job

  16. Upstart Blogger added these pithy words on 11 Jul 07

    Sorry, Amit. What you’re describing is too complicated for a simple cron job, I think. Your question is beyond my abilities.

  17. kedar added these pithy words on 05 Aug 07

    Hi Robert,
    You write very good article of setting cron job. I get a good knowledge because of you.
    But i hav one query, i want to send newsletter mails to more than thousands of email addresses, how can i do this, may i do this using cron job? we may not send these mail at a time because mail server goes down or block.. how can i do this replay me as soon as possible..

  18. Upstart Blogger added these pithy words on 06 Aug 07

    @kedar: I’m sorry, but I’m not really sure how best to do this. Most hosts will limit your email to prevent spam. Assuming you’re not sending out spam, your host may offer some kind of email newsletter program that will work. There are numerous free or inexpensive email services that will do this. Try a Google search.

  19. Mukesh added these pithy words on 16 Sep 07

    Hi,

    This is wonderful place for setting a cron job. But I have one issue with running a cron job. Say in between while running a cron job, due to any reason, it gets stop or say cron job is not finished successfully. Can we roll back the entire process. In a situation where large data deletion or insert is done this may create problem. Or any other way to overcome this problem.

    Thanks
    Mukesh

  20. MadNut added these pithy words on 07 Oct 07

    I have AN Hostinga account also, but in CRON “advance” it has only 1 set of field i need at least 12 how can i add more than 1 CRON command ? its for a paid script i just bought,

  21. Upstart Blogger added these pithy words on 07 Oct 07

    @MadNut: Use the standard cron setup. I don’t think there’s a limit to how many you can set up there.

  22. ste added these pithy words on 10 Nov 07

    hey thanks for this part

    php /home/[your username]/public_html/rss/import_feeds.php

    i didnt know that, and i will certainly try it

  23. Rohit Gupta added these pithy words on 13 Nov 07

    Hi,

    If Cpanel doesn’t contain a cron manager, then how do u create cron jobs, if your php/mysql application is hosted on (a) shared unix/lynix web server (b) windows web server.

    Pls advice

  24. Rebecca added these pithy words on 20 Nov 07

    I am trying to set up cron jobs to visit each of my subdomains daily, so they will automatically update themselves. They need to be visited once per day to do this. What command do I use? Rebecca

  25. Upstart Blogger added these pithy words on 20 Nov 07

    @Rohit: If you have cPanel, it should have a cron manager. If it doesn’t, you’ll have to use Unix and I can’t tell you how to do that.

    @Rebecca: I have no idea what you’re trying to do. You’ll need some kind of script and run it once a day for each domain. I’m sorry, but again, I can’t help you.

  26. artofnet added these pithy words on 29 Nov 07

    Hi,

    Your article is very useful and very helping.
    I’m the one who has helped by your article to set up a cron jobs on my site.
    Once again thanks for great article.
    Cheers…

  27. Rajiv added these pithy words on 17 Dec 07

    The information to run the automated php script is very useful

  28. Alfred added these pithy words on 26 Dec 07

    thanks a lot, was so irritated trying everything and not getting it to work.
    it needed the php before the command i guess

  29. Anthony added these pithy words on 27 Dec 07

    Very useful information.
    I could not understand why my cron job was not running and it was just down to the php in front of the path.
    Looks like that was the problem for a lot of other people as well !

  30. alprof added these pithy words on 24 Jan 08

    the corn job it is effected bad when i am writing wrong sentences.
    plz help me sooooooooonas

  31. Demexii added these pithy words on 28 Jan 08

    Thanks for the help. I wasn’t sure what I was doing and having someone else explain it was helpful.

  32. John added these pithy words on 24 Feb 08

    Having problems setting up a Cron Job for mail list using PHP List for the newsletter and database. Hosting on Cpanel. I have tried several scripts and one works from the command line but not through the Cron Job Settings.
    Any suggestions?

  33. Hasanur added these pithy words on 29 Mar 08

    HEllo “Upstart Blogger 07 Oct 07″

    Thanks for your article …

    I have set cron but getting email with error
    in the path box if i dont put this url

    /home/username/public_html/cronjobs/email.php
    then it reads evry line of email.php and notice error every line..

    but if I put this path
    php/home/hasanur/public_html/cronjobs/email.php
    then says “no file in this directory..”

    would you please help me ?

    thanks

  34. Kleidi added these pithy words on 09 Apr 08

    Hello man and thank you for the tutorial ;)
    I have a question… i’m using joomla with fireboard forum that didn’t update stats automatically and i need to make it manually or to set a cron jobs. The link that i click to update stats is http://www.mydomain.com/administrator/index3.php?option=com_fireboard&task=recount !
    Can you tell me how to set the cron job for this task?

    Thank you in advance and have a nice day ;) ! I’m waiting for your reply!

  35. Scott added these pithy words on 10 Apr 08

    Is it possible to run a cron job say every 33 days, i know on standard it doesn’t give the option, but on advance you could change it manually, i was wondering if it would work if i set it for say 33 days, or 102 seconds or 80 minutes, something like that, you get the idea don’t you ??

  36. hammy added these pithy words on 21 Apr 08

    thanks a lot it is usefull for a newbie like me to learn something, thanks a lot !

  37. php-web-developer added these pithy words on 02 May 08

    Can you tell me how to set the cron job for Advanced (Unix Style)

  38. Dimi added these pithy words on 01 Jun 08

    Thanks, i’m searching for that but can’t find how to create log file for cron jobs to monitor them.

    Regards

  39. Guido den Broeder added these pithy words on 05 Jun 08

    Hi,

    What is the exact path that I need in a php command? I tried the full url to the .php file, i.e. I entered

    php http://www.mydomain/wiki/maintenance/update.php

    but that didn’t work and I didn’t receive an email.

    Regards,

    Guido

  40. Guido den Broeder added these pithy words on 05 Jun 08

    Never mind, it needs to be

    php /home/myusername/public_html/wiki/maintenance/update.php

    Regards,

  41. Fit Seniors added these pithy words on 20 Jun 08

    This was so easy to install…thanks for the guide. Easy enough for me to understand. :)

  42. Samuel added these pithy words on 21 Jun 08

    Thank you it’s very useful.

  43. Aditya Mooley added these pithy words on 19 Aug 08

    Thanks. I was looking for this for a long time.

  44. My Head Hurts added these pithy words on 22 Aug 08

    Hi

    Thanks very much for your article.

    I’ve a problem (suprise) which I thought one of your first comments would solve. Unfortunatley it doesn’t appear to have.

    My problem:-

    Cron ‘Command to run’:
    php /home/*myuser*/public_html/admin/includes/cronrefresh.php?fd_refresh=1

    When I put this in and it runs I get an error email stating:

    /bin/sh: php/home/*myuser*/public_html/admin/includes/cronrefresh.php?fd_refresh=1: No such file or directory

    I’ve tried various other path permutaions but I’m sure this is the right path.

    I see that I’m getting the /bin/sh: in the error, but I never put this in the ‘Command to run’. This would seem to me that the php is not being run.

    (I say this as you start off by saying a php command should start with ‘php’ and a shell script starts ‘/bin/sh’)

    Have I guessed this correct and if so how do I get rid of the ‘/bin/sh’?

    Very many thanks
    Bud

  45. Alain added these pithy words on 14 Nov 08

    I need run my cron job weekly, all sunday at mid night, how set hour, mins, month, etc?

  46. Pat added these pithy words on 02 Dec 08

    Hey thank you for posting this- I had no idea how to set the time and this was perfect!!

  47. jamie added these pithy words on 24 Jan 09

    Thanks for the tip of using php at the front of the command line.

    Very useful to use cron for testing automatic scripts. I set my first test cron script to send me an email every minute using mail(). Works nicely. Now I’ve got that working I can start creating other automated scripts.

    Many thanks.

  48. Genesis added these pithy words on 22 Feb 09

    Hi I am making a CronJob for my forum and would like to let you know that I am getting a Permission Denied when it does the cronjob… any ideas on how to fix that?

  49. steve chan added these pithy words on 13 Jan 10

    First of all what a great tutorial!

    I was just wondering if that space is meant to be at the end of the word php on:

    php /home/[your username]/public_html/rss/etc.php

    I got it working but my emails are telling me that there is no such directory that I have specified.

  50. steve chan added these pithy words on 13 Jan 10

    Wow, its working, I guess the space is meant to be there!
    Thanks a trillion for sharing your insightful knowledge.

  51. Azril added these pithy words on 19 Nov 10

    This example is perfect! thanks.

  52. Kavi added these pithy words on 25 Nov 10

    I am getting mail, but i am also getting one Cron Daemon mail from that server having message as X-Powered-By: PHP/5.2.9
    Content-type: text/html
    I dont want this to be send.
    Any Idea?

  53. Nicole added these pithy words on 10 Jan 11

    Thanks! This is cool.

    Upstart Blogger must be too busy to solve everyone’s problem.. lol.

  54. Flavio added these pithy words on 14 Apr 11

    Just a bit busy, but I’m working on responding to everyone.

Post a Comment

Comments are moderated. It may take some time before your comment appears. Please be patient. Comments become the property of Upstart Blogger.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: Please post support questions in the Forums. Be sure to read the Upstart Blogger WordPress Themes FAQ before posting. Thanks!

Your email is never published nor shared. Required fields are marked *

*
*

Hosting that doesn’t suck. Use code UPSTARTBLOGGER for 3 free months.

Return to Top