How to create Scheduled Tasks in Plesk
Creating scheduled tasks (also known as cron jobs) in Plesk is a powerful way to automate various scripts and commands on your server. These tasks can be set up to run scripts written in PHP, Perl, Python, or any other scripting language, or to execute system commands at predefined times or intervals. Here’s a step-by-step guide on how to create scheduled tasks in Plesk:
Step 1: Log into Plesk
- Access Plesk Panel:
- Open your web browser and navigate to your Plesk login URL. This is typically in the format of
https://yourserverip:8443
orhttps://yourdomain.com:8443
. - Enter your Plesk username and password to log in.
- Open your web browser and navigate to your Plesk login URL. This is typically in the format of
- Find Scheduled Tasks:
- Once logged in, look for the “Tools & Settings” option on the left sidebar (you need to have administrative privileges). If you are a domain user, you’ll find the “Scheduled Tasks” option directly in the domain’s dashboard.
- Click on “Scheduled Tasks” or “Cron jobs”.
Step 3: Add a New Task
- Create a New Task:
- In the Scheduled Tasks section, click on “Add Task”.
- You will be presented with a form to configure the new scheduled task.
Step 4: Configure Task Settings
- Task Type:
- Select the type of task you want to create. You can choose to run a command, a PHP script, or a script in another language.
- Command Details:
- For a command, enter the full path to the command or script you wish to run. For example,
/usr/bin/php /var/www/vhosts/yourdomain.com/httpdocs/script.php
. - For PHP or other scripts, browse and select the script file you want to run.
- For a command, enter the full path to the command or script you wish to run. For example,
- Schedule Timing:
- Set up the schedule for your task. You can choose from common presets or use a custom cron expression for more specific timing.
- Define how often the task should run – every minute, hour, day, week, month, or set up a custom schedule.
Step 5: Additional Settings (Optional)
- Specify Description and Other Options:
- Optionally, add a description for your task.
- You can also specify additional settings like the command execution environment, which includes setting up HTTP headers if it’s a web request.
Step 6: Save the Task
- Save the Scheduled Task:
- Once you have configured all the settings, click on the “OK” or “Save” button to create the scheduled task.
- The task will now run automatically according to the schedule you set.
Best Practices and Tips
- Test Your Script: Before scheduling, manually run your script to ensure it works as expected.
- Logging: Consider redirecting the output of your script to a file for logging purposes, especially for debugging. For example, add
>> /var/log/my_script.log 2>&1
at the end of the command. - Resource Usage: Be mindful of the resources your script uses, especially if it’s running frequently.
- Security: Ensure that your scripts are secure and cannot be exploited by unauthorized users, especially if they are accessible from the web.
Conclusion
Creating scheduled tasks in Plesk is a straightforward process that can automate many routine tasks, from site backups to script execution for website maintenance or data processing. By following these steps and adhering to best practices, you can effectively manage and automate tasks on your Plesk-managed server.