Follow

Troubleshooting common issues with cron jobs

  • Applies to: Grid
    • Difficulty: Medium
    • Time Needed: 15
    • Tools Required: SSH, vi knowledge
  • Applies to: All DV
    • Difficulty: Easy
    • Time Needed: 10
    • Tools Required: SSH, vi knowledge

Overview

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

Although we can't directly troubleshoot your commands (please see 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 at /path/to/script.phpand 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). The file 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 are 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.

Additional troubleshooting

The DV servers contain a cron log that will record all cron activity and any errors encountered. 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, then select Preferences. Specify your email address here and any output will be emailed to you.

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.

Resources

For more information on how to setup a cron job on your service, please see:

Was this article helpful?
1 out of 1 found this helpful

Comments