This article explains how to set cron jobs up on your Media Temple server. Cron is a server utility that allows you to set up scheduled tasks. You might want to set up a cron job to do any of the following.
- Check disk space.
- Run a maintenance script.
- Delete files periodically.
Please be aware of the following limits that are enforced for all cron jobs on the Grid.
- 5 minutes of CPU time
- 15 minutes of actual time
- 200 simultaneous file descriptors
- 100MB of RAM
- 5 simultaneous processes
If you'd like to gain a better understanding of cron, consider checking out this beginners guide to cron published on the Media Temple blog:
READ ME FIRST
Media Temple supports the basic cron functionality for your Grid. Troubleshooting specific cron jobs is outside the scope of our support. Please take a moment to review the Statement of Support.
- Sign in to the Account Center.
- Select your domain from the DOMAINS tab.
- Click Cron Jobs from the FILE MANAGEMENT panel.
- Click Add Cron to continue.
- Enter an email address for notification purposes. (optional)
- Fill out the Command or script to execute field. (required)
Example of a disk usage command or script to execute: This is a simple one-line command.
du -sh /home/00000/
Replace 00000 with your site number.
If your cron is more than one line, it is highly recommended that you save it as a script (see the next example for details). If you wish to run a custom script, make certain you've uploaded the script to a directory on your server. Then provide the complete path to your script. This is an example of a full path to a script. Below are several examples of various scripts being run from the command line:
- Example of running a Shell or Perl script
- Example of running a PHP script:
- Example of running a PHP5 script:
- Example of running a PHP7 script:
- Example of running a PHP script via curl. The command-line curl client allows you to fetch a page from a web server and the output is sent to you via email (if the email field above is completed).
Another option for curl includes adding the silent option so that you will not receive emails unless errors are reported.
curl --silent http://example.com/script-name.php
- Example of a disk usage command or script to execute: This is a simple one-line command.
- Choose the time and frequency with which you would like to run your script. You can use some of the predefined values like Every hour or Every 5 Minutes. If you use the Specify option, the list of numbers allows you specify what minute of the hour you want the cron job to run. For example, if you select '3', then the cron job will run at 10:03, 11:03, 12:03, etc. You can select multiple numbers, but they must be at least five minutes apart.
The maximum frequency that your script can be run is at five-minute intervals. The cron will use the PST time zone.
- Review the values you have entered into each field and click SAVE. If you selected to have the output emailed to you, it should arrive shortly after the command or script has finished. The screen will refresh and your list of cron jobs will be listed.
- If you are running a shell script instead of a built-in command, you must make certain that your script is executable and has the correct ownership. The command following will make your script executable.
chmod +x /path/to/script
- In any field, you can select multiple settings by holding the Ctrl-key (PC) or command-key (OS X) down while clicking on your selection to highlight multiple entries.
- Running a php script via cron will not load a site's php.ini. This can be forced with the following flag.
This will allow users to, e.g., retrieve remote data (by turning on allow_url_fopen) using a php script outside of the web root.
READ ME FIRST
Media Temple supports the basic cron functionality for your standard configuration DV server. Troubleshooting specific cron jobs is outside the scope of our support. Please take a moment to review the Statement of Support.
Plesk makes it very easy to schedule cron jobs. Note that you can set up either a server-wide cron job or a domain-specific cron job.
- Plesk Onyx cron documentation: Scheduling Tasks
1. Log into your Plesk control panel and click on Scheduled Tasks. This is located on the right side of the panel and is the same for Power User and Service Provider views.
2. Click on Add Task
3. Use the form to input your cron job. The below example creates a backup each day at midnight. You may want to use the Run Now feature to test your cron prior to setting it. You also have the option to receive email notifications. Click OK once your cron job is set up properly.
4. Plesk should return a notification letting you know that the cron job has been created.
- Log into your cPanel account
- Navigate to the Advanced tab. Select Cron Jobs.
- Input an email if you wish to receive notifications for cron jobs that have an output.
- The below example is set to run a cron ever 15 minutes. Insert your desired command in the Command box. Then click Add New Cron Job.
Examples and Tips
The scheduling format is the same in Plesk as it is for manual cron jobs. There are five scheduling fields followed by a command string.
- Minute: Choose 0-59
- Hour: Choose 0-23 (24-hour clock)
- Day of the Month: Choose 1-31
- Month: Choose 1-12
- Day of the Week: Choose 0-7 (0 and 7 are both Sunday)
- Command: This is the command that will be entered in the crontab. For a quick test, try running the command from SSH first. Make sure you are logged into SSH as the appropriate user (the one you clicked on to set the cron job in the first place).
More Scheduling Options
- List: 0,15,30,45 in the Minute field will run every quarter hour.
- Range: 4-6 in the Day of the Week field will run on Thursday, Friday, and Saturday.
- Every: * means "every." If you put * in each field, the job will run every minute, all the time.
- Divide: / allows you to specify a time that is divisible by a certain number. For example, */2 in the Month field will run on even months only.
- Results will be emailed to the user who owns that job by default, at the hostname of the server. Example: If you set up a job under your domain, with the user domainuser, the email will go to email@example.com. You can designate a different email address if desired. To do this, follow Steps 1-3 of the Plesk walkthrough (linked above), then click on Preferences. Here, you can set a new email address.
Remember that the first five characters are scheduling characters. You do not need to copy and paste these into the Plesk control panel - just the command part. On the other hand, if you are editing the crontab manually, you should include the entire command.
- Check disk usage every hour on the hour and email the results to firstname.lastname@example.org.
0 * * * * df -h | mail -s 'Email subject' email@example.com
- Run a perl script at 2:15 PM every Monday. Standard output will not be emailed, but errors will still go to the standard email address for this cron user.
15 14 * * 1 perl /full/path/of/script.pl > /dev/null
- Delete a file on the 15th and 30th of each month. No output (standard or error) will be emailed.
* * 15,30 * * rm -f /full/path/to/file &> /dev/null
Edit Cron Manually
Media Temple does not support manually editing your crontab outside of the Plesk control panel.
You can do even more with cron by using the manual crontab editor. To open the crontab for editing, complete the following.
- Log into your server with a root or sudo user via SSH.
- Check for existing jobs (not strictly necessary, but a good idea to prevent conflicts).
- Open the crontab for editing.
- The file has been opened using the vim. Make your desired changes, then save.
Your new cron job should now run as specified.
You can use scheduling shortcuts when you edit your crontab manually. The shortcut comes before the command in place of the five numbers. See the following table for possible values.
|@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 * * * *".|