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
READ ME FIRST
(mt) 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.
- Example of running a Shell or Perl script
- Example of running a PHP script via command-line
- Example of running PHP5 via the command-line
- Example of running a PHP script via curl. 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).
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 in 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
(mt) 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.
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
- When using the Service Provider View (you have a sidebar)
- Under Hosting Services, select Domains.
Choose your domain. Click Open in Control Panel. The Power User view will display.
For your domain, click Open in Control Panel.
- When in the Power User view (the Control Panel)
Select the Websites & Domains tab. Click Scheduled Tasks.
Select Scheduled Tasks.
- Select the user.
Click Schedule New Task.
- Specify when to run the command by assigning time/day values. Complete the Command.
- Switched on
- Day of the month
- Day of the week
- Click OK.
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 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
(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, 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.
- You can edit the file with vi. Make your desired changes, then save.
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 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 * * * *".|
There are many cron resources online.
- HowtoForge has additional examples and tips.