Support / KnowledgeBase

 
Search the KnowledgeBase Search

Using Cron on a (dv) Dedicated Virtual Server

  • Applies to: (dpv) Nitro, All (dv)

  • Difficulty: Easy

  • Time needed: 5 minutes

  • Tools needed: None

 

This article helps to explain how to set up a cron job on (dv) Dedicated Virtual Servers.


DETAILS:

Cron is a service that is used to schedule commands to be run at certain times. This document does not apply to (ss) Shared-Servers. For that please read FAQ: Cron jobs for (ss) Shared-Servers.

To set up a cron job through the Plesk interface:

  1. Log into Plesk as the desired user and navigate to the domain that the cronjob should be scheduled for.
  2. Click on Crontab or in a (dv) 3.x Click on Scheduled Tasks
  3. Click on Add New Task
  4. The format of the fields follows the basic cron format.
    • Minute for the cronjob to be run, this value is 0-59
    • Hour, this value is 0-23 (24 hour clock)
    • Day of the Month, this can be 1-31
    • Month, 1-12
    • Day of the Week, 0-7 with 0 and 7 being Sunday
    • Command, this is the fully qualified cron command to be entered into the crontab

    All of the fields can have lists (0,15,30,45 in the minute field will run on every quarter hour), ranges (4-6 in the Day of the Week field will run on Thursday, Friday and Saturday), and the * character to match every instance. Even some simple expressions will work (Sunday in the day of the week field will work for Sundays, */2 in the Month field will work for even months only) By default the return of the command is emailed to the admin email user, but this can be changed in the 'Send Crontab messages to address' box in the 'Crontab Tasks' view.

    Examples:

    • You want check your disk usage and have it emailed to you every hour on the hour. This entry would look like this:
      0 * * * * df | mail -s 'email subject' username@mt-example.com
    • These values would go into the Plesk fields in order.
    • You want a perl script to run at 2:15pm every Monday. You don't want any output emailed to you, but if the script has any errors you'd like them to be sent.
      15 14 * * 1 perl /full/path/of/script.pl > /dev/null
      
      The command portion should be put into the 'Command' field including the '>> /dev/null' part which tells cron to discard any regular output.
    • You want to delete a file on the 15th and 30th of each month and you don't want any output including errors sent to you.
      * * 15,30 * * rm -f /full/path/to/file > /dev/null 2>&1 
    • Click OK to install your new cronjob.

The functionality of some of the cron extensions is not accessible via the Plesk interface but are still available, this includes the special strings in place of the first five fields:

string meaning
------ -------
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".




















Revisions:

07-15-2009: Fixed Formatting
 

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