How to create Scheduled Tasks in Plesk

- by

In this episode I’ll show you how to create Scheulded Tasks in Plesk. I’ll explain where to find them (for admins and customers), how to execute them and what all those cryptic fields mean. I’ll also show you how to mute the output of the commands you execute so you won’t be bothered with emails you didn’t ask for.

Scheduled Task is another name for Cron Job, and it’s something you want to run on a regular basis, like a script file. Plesk itself does not execute your task. Instead it will give you a nice interface to add the parameters you need for the Linux crontab command (or the equivalent on Windows, I believe it’s called at or schtasks).

 

Cryptic Numbers

The cryptic numbers in each field are crontab parameters. Numbers for those fields correspond to their description (i.e. 0-59 for minutes, 0-23 for hours, etc).

One thing of note (and confusion) is how to define endless repetitions. We can do this with the asterisk and slash combinations.

  • * means “every”, as in “every minute”, “every hour”, “every day”
  • */4 means “every 4”, as in “every 4 hours”
  • 5-11 means “every number in between”, such as 5,6,7,8,9,10,11

To find out more about the crontab command, head over to a great nixCraft article here:

 

Muting Output

By default Plesk will send you an email with any output a script or command may generate. You can avoid this by diverting all output to /dev/null. This is a virtual partition that magically makes things disappear.

In the video I’m using a fictitious script /var/script.php. To divert its potential output I would use

/var/script.php > /dev/null 2&gt&1

 

A note about Script Files

If you’re executing BASH, PHP, Python or any other script, make sure your files contain the she-bang at the very beginning to that your server can find the correct path. Here’s an example for how a PHP script should start:

#!/usr/bin/php

Note that web files that are designed to run in a browser cannot be called that way. You need to call those using cURL or wget.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

4 thoughts on “How to create Scheduled Tasks in Plesk”

  1. Depends on how complex your script is. If its just a few lines of commands, the vi editor from the command line works well. For larger scripts, you can use the same technique and paste the contents into a vi session. You could also download a script to the server from an external source (like GitHub).

    Don’t forget to fix those file permissions!

  2. By the way I cant open the task.php script .the file shows me these:

    v俍p几l2伋淔iP$貣?5剦am凿0?@挭u$?Zfザ?%Vo*迴V7?徥鐔6i柏別?╄Vb\謹?A勭淧~|z葵厇鄬誻u杆脌=Bッ~烾????=&?|?纲挌??狳馔K廞愆
    卐愦>?’1h毐?q斒?
    澏騶o,纰??扡S?WfQ ??_Pl縡i案$蜓:U2貉邹縴+垔M鑛槱萆Uy斘Py患厠雜岁賧犠X屆砿f 磢爅隄st 罫嚷v?.
    菌壛躾;/W’@ 凁儑^鬍n椺’鏱x焧k`n湖V2cw’焲g?瓃簂絑L猁n{c-沔??剓/k?锖?謡w?元ba閇JkyP=崵?频霺薂繵G賥?皇.萳湎枱X%i早B[?因r
    v埃D?4﹌峆眨s7W熹L筈魈鴳穇_?択5???Mc仏呾h}W:?{NG鍟?€鄉/傀羰?(
    鬟A唍蓠E髻?3显a笆8?暭z岅? 丞ヲ偯?e渾C{濩D枱虃=闊_宸?抳巃~狨0X栌た*h儚弙?$k?謈?肙z雟貃彄?}阍x/n?.l?k盼璊瀥y徜咂レ4萾z朇擄穋羯9?鍣DFU慕鱮
    @??RnU竖↘坅?:

    can you please help ?I can not read my file .

  3. task.php is likely a Plesk system file, and like most system files it’s encrypted. As a rule of thumb, you should NEVER EDIT SYSTEM FILES because your changes will be overwritten should the file ever be re-generated. Lucky for you, in this case it’s impossible to edit it anyway.

    You should write your own script file and call it anything you like, then add the full path to the Scheduled Tasks dialogue in Plesk. If you’re only running a single command, you don’t even need a script file, you can pass all the parameters in the dialogue.

    Good luck!

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.