Using Cron
Overview
Cron is a server utility that allows you to set up scheduled tasks. You might want to set up a cron job to:
- Check disk space.
- Run a maintenance script.
- Delete files periodically.
Limitations
Please be aware of the following limits that are enforced for all cron jobs on the (gs) Grid-Service:
- 5 minutes of CPU time
- 15 minutes of actual time
- 200 simultaneous file descriptors
- 100MB of RAM
- 5 simultaneous processes
READ ME FIRST
(mt) Media Temple supports the basic cron functionality for your (gs) Grid-Service. Troubleshooting specific cron jobs is outside the scope of our support. Please take a moment to review the Statement of Support.
Instructions
- Sign in to the AccountCenter.
-
From the Overview page or Domains tab, select your primary domain to access your (gs) Grid-Service Control Panel. See Figure 1.

Figure 1. Click to view a larger image. -
Click on the Cron Jobs icon near the bottom of the page, see Figure 2.

Figure 2. -
Click on the Add new cron job button near the top of the page, Figure 3.

Figure 3. -
For this first example, we're going to run a simple disk usage command and send the email to amy@gs-example.com.

Figure 4. -
Fill out the Command to Run field.
- Notification Email: We will send this to amy@gs-example.com. You may send the notification to any email of your choice.
-
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, we recommend saving it as a script. See the next example for details. If you wish to run a custom script, make sure 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.
-
To run a Shell or Perl script:
/home/ -
To run a PHP script via command-line:
php /home/00000/data/script-name.php -
To run as PHP5 via the command-line:
php5 /home/00000/data/script-name.php -
The command-line curl client allows you to fetch a page from a webserver and the output is sent to you via email (if the email field above is completed). To run a PHP script via curl:
curl http://example.com/script-name.phpAnother option for curl is adding the 'silent' option so you won't receive emails unless errors are reported:
curl --silent http://example.com/script-name.php
-
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.
NOTE:
The maximum frequency that your script can be run is in 5 minute intervals. The cron will use the PST time zone.

Figure 5. -
Review the values you have entered into each field and click the save button. 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, see Figure 6.

Figure 6.
Notes
-
If you are running a shell script instead of a built-in command, you must make sure 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 (see screenshot above for an example).
-
Running a php script via cron will not load a site's php.ini. This can be forced with the flag:
-c /home/00000/etc/php.iniThis 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
(mt) Media Temple supports the basic cron functionality for your standard configuration (dv) Dedicated-Virtual Server. Troubleshooting specific cron jobs is outside the scope of our support. Please take a moment to review the Statement of Support.
Instructions
Parallels provides a thorough walkthrough for accessing the cron feature through the Plesk control panel. Note that you can set up either a server-wide cron job or a domain-specific cron job.
- This link is for the Plesk 10.1.1 documentation: Plesk documentation
- This link is for the Plesk 8.6 documentation: Plesk documentation
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 host name of the server. Example: If you set up a job under your domain, with the user domainuser, the email will go to domainuser@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.
Examples
TIP:
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 username@example.com:
0 * * * * df -h | mail -s 'Email subject' username@example.com
- Run a perl script at 2:15pm 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
CAUTION:
(mt) 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:
- 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):
crontab -l -
Open the crontab for editing:
crontab -e -
You can edit the file with vi. Make your desired changes, then save.
TIP:
vi tip: Press "i" to enter "insert mode" so you can type and copy/paste. Press "Esc" to exit "insert mode" when you are done modifying the file. Type ":wq" to save and quit.
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 table for possible values:
| 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 * * * *". |
Additional reading
There are many cron resources online.
- HowtoForge has additional examples and tips.