Support / KnowledgeBase

 
Search the KnowledgeBase Search

Troubleshooting Common Issues with Cron Jobs

  • Applies to: All Service Types

  • Difficulty: Medium

  • Time needed: 5 minutes

  • Tools needed: None

 

NOTE:

For more information on how to setup a cron job on your service, please see http://kb.mediatemple.net/questions/243/

Details:

Cron jobs are commands that your service runs at a specified interval, and as such can be difficult to troubleshoot.

Although we can't help troubleshoot your commands per our Scope of Support, some of the most common cron mistakes are:

  1. Using relative paths. If your cron job is executing a script of some kind, you must be sure to use only absolute paths inside that script. For example, if your script is located here:

    /path/to/script.php


    And you're trying to open a file called "file.php" in the same directory, you cannot use a relative path such as "fopen(file.php)". It must be called from its absolute path, like this: "fopen(/path/to/file.php)". This is because cron jobs do not necessarily run from the directory in which the script is located, so all paths must be called specifically.
  2. Permissions being too strict. Please be sure all scripts, files, and folders that are being used are set to "executable". In the case of writing to a file or folder, it MUST be writable.

    In your server's shell, this is the command that will make a file executable:

    chmod +x <file>
    

  3. Not specifying what type of file you are running. For instance, if you are trying to run a PHP script via the cron job, you must specify that the file being run requires the PHP language to run it. For instance, if the file is "/directory/script.php", the cron should read "php /directory/script.php". This goes for all scripts, regardless of the interpreter.

Further Troubleshooting:

(DV) DEDICATED VIRTUAL CUSTOMERS:
The (dv) Dedicated-Virtual servers contain a "cron log" that will record all cron activity, and any errorsencountered. You can view this file at /var/log/cron

You can also have your server send you an email with details of each cron job. To do this, simply select the domain under which you're running the cron job, and then click Crontab. Select the user you are running the cron job under, and then Preferences. Specify your email address here, and any output will be emailed to you.

(GS) Grid-Service Customers:
In your Cron jobs tab, you can click the "Edit" button next to your cron job, and then enter an email address for the "notification email". This will be helpful for troubleshooting your script.

Revisions:

07-07-2009: Article Creation

User Comments

No visitor comments posted. Post a comment

Fields marked with an asterisk(*) are required. Comment on this article

Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue