Plesk 10: Cron Job Setup | prosoxi.com

Categorized | Plesk

Plesk 10: Cron Job Setup

This tutorial will show you how to setup a cron job using Plesk 10 on a Linux VPS. Like cPanel, Plesk is a widely available hosting control panel, providing a GUI through which users can configure their hosting.

What is a cron job?

A cron job, also referred to as a ‘scheduled task’, is simply a command (e.g. go to a particular URL) which is executed at a specified time.

You may, for example, setup a cron job to access the URL of a PHP file (e.g.http://www.example.com/test.php) once every day. Accessing that PHP file could in turn run whatever code the file contained, and that code could then in turn initiate other tasks such as creating a database backup or clearing log files.

In short, cron jobs can be a useful way of performing, or initiating, (recurring) tasks.

So, let’s get started…

1. Log into Plesk and click the ‘Subscriptions’ link

Logging into Plesk will bring you to your Plesk panel’s home page.

We first need to select which VPS subscription we want to associate the cron job with. So, click the ‘Subscriptions’ link in the left sidebar

Plesk 10 home

 

2. Select the relevant control panel

Click the ‘Control Panel’ link for the subscription you want to associate the cron job with. In this example we only have one subscription (‘example.com’, which is subscribed to our ‘Unlimited’ plan) so we click its ‘Control Panel’ link

Plesk subscriptions

 

3. Navigate to the ‘Scheduled Tasks’ page

Clicking the ‘Control Panel’ link opens our chosen subscription’s control panel home page. Cron jobs are categorised under ‘Websites & Domains’ so click the ‘Websites & Domains’ menu tab

Plesk control panel home

 

and in the ‘Websites & Domains’ section scroll down and click ‘Show Advanced Operations’

Plesk control panel websites and domains

 

Now click ‘Scheduled Tasks’ (‘Scheduled tasks’ is how Plesk generally refers to cron jobs)

Plesk control panel advanced operations

 

This opens the ‘System Users’ page. Click on the name of the subscription’s system user

Plesk control panel system users

 

4. Schedule a new task

On the ‘Scheduled Tasks’ page click ‘Schedule New Task’

Plesk - Cron - Schedule New Task

 

which will load the ‘Schedule a Task’ form (in this screenshot we’ve already filled the form fields)

Plesk - Cron - Schedule A Task

 

Our cron job is switched on and will fire on the fifteenth minute (15) of the third hour (3) of every day of the month (*) of every month (*) of every day of the week (*) and execute the command
/usr/bin/wget -O - -q http://www.example.com/test.php

Or, to put it more clearly, our cron job will fire every day at 3.15am and hit the URL
http://www.example.com/test.php

Cron job configuration

There are three key parts to our cron job configuration:

  • Is the cron job switched on or not? - i.e. should it fire or not?We want our cron job to fire, so we ensure the ‘Switched on’ checkbox is checked.
  • What time should the cron job fire?Times can be set for each field by entering numeric values, or in the case of ‘Month’ and ‘Day of the week’ by selecting from a dropdown.

    The basic values which can be entered are:

    Minute 0 to 59
    Hour 0 to 23
    Day of the month 1 to 31
    Month 1 to 12, or choose from the dropdown
    Day of the week 0 to 6 (0 for Sunday), or choose from the dropdown

    Further manipulation of cron times can be achieved with the asterisk (*):

    • On its own, an asterisk means ‘every’. In our example we use an asterisk to represent every day of the month, every month, and every day of the week
    • Combining an asterisk with a forward slash and a number means ‘every x number of’. So, if we instead wanted our cron job to fire every three hours we’d replace the ’3′ in the ‘Hour’ field with ‘*/3′

    Plesk - Cron every three hours

    Note: Numeric values, forward slashes, and asterisks will probably be sufficient for timing the majority of cron jobs, however cron expressions can be further extended using other special characters (comma (,), hyphen (-), question mark (?), L, W, and pound (#)).

  • What command should the cron job execute?We’re using the command /usr/bin/wget -O - -q http://www.example.com/test.php

    This command is made up of three parts:

    • /usr/bin/wgetFirstly, we specify the path to the utility we want to use to execute the command. Here we’re using a Unix utility called ‘Wget’, which is located on our server at ‘/usr/bin/wget’.

      Note: alternative Unix utilities which could be used include lynx and curl.

    • -O - -qSecondly, we specify what to do with any output generated as a result of our command executing.

      All we want to do is retrieve the URL http://www.example.com/test.php, so we set wget options which will discard any output and prevent cron’s default behavior of sending an email notification to the user executing the command (i.e. us):

      -O -
      takes any output (‘-O‘) and sends it to stdout (‘-‘)

      -q
      turns off any output. This means both that the output we’ve sent to stdout is effectively discarded, and that cron will not send us email

    • http://www.example.com/test.phpLastly, we specify the URL which the command should retrieve.

Create it

Click the ‘OK’ button. The cron job will be created and a confirmation message shown

Plesk - Cron - New Task Scheduled

Our cron job is now listed under ‘Scheduled Tasks’ and ready to go.



One Response to “Plesk 10: Cron Job Setup”

  1. nikmauro says:

    To fix the problem and restore behaviour to how it worked in previous versions of Plesk, all you need to do is run the following command:
    /usr/local/psa/bin/server_pref -u -crontab-secure-shell “/bin/sh”

    Source

    http://forum.parallels.com/showthread.php?t=110192
    http://download1.parallels.com/Plesk/PP10/10.2.0/Doc/en-US/pdf/plesk-10-administrator-guide.pdf
    http://forum.parallels.com/showthread.php?t=110212
    http://forum.parallels.com/showthread.php?t=110192
    http://shaun.net/2011/09/solving-plesk-10-3-1-cron-issues/

Trackbacks/Pingbacks


Leave a Reply

 

Advertise

Whocallsme.gr Widget Lookup