Support / KnowledgeBase

 
Search the KnowledgeBase Search

FAQ: Cron jobs for (ss) Shared-Servers

  • Applies to: (ss)

  • Difficulty: Medium

  • Time needed: 5 minutes

  • Tools needed: None

 

This article answers many common questions about cron on our (ss) Shared-Servers.

DETAILS:

This FAQ applies to (ss) Shared-Servers, if you are on the (dv) Dedicated Virtual Server product line you should read our article Using Cron on a (dv) Dedicated Virtual Servers

Q. Will (mt) Media Temple allow me to set up a cron job on my (ss) Shared-Server?
A. Yes, but they must fit the following requirements:

  1. The script/program that cron will execute must be a web based script hosted on our (ss) product line and provided to us in URL format (http://www.domain.com/path/to/script.cgi)
  2. The cron job will access the URL provided and all output generated by the cron job will be silently discarded
  3. The maximum execution frequency allowed for a cron job is once per hour

Q: How do I request a cron job be added for my server?
A: File a support request in the AccountCenter. Be specific as to where your script lives and how often you'd like it to run.

Q. Why am I required to make the script a web based script?
A. Requiring scripts that will be run from cron be web accessible ensures that you can test the script in the EXACT same environment as it will be in when it is executed from cron. This makes it much easier for you to know that your script is working properly. Also, as a web based script, every time it is called, there will be an entry in you http logs. Because of this, you can always verify that the cron job is being executed.

Q. I have a script that needs to be run from cron, but it is not web based. How can I make this work?
A. Believe it or not, this is a relatively simple problem to address. What you need to do is write a wrapper script. We don't expect everyone to be a programmer, so here is a brief tutorial on how to implement a wrapper.

Let's say you have a script called example.pl that you uploaded to '/var/www/html/bin'. To run properly, it needs to be executed from /var/www/html. Given this scenario, you would create a script called web.sh which contains the following:

#! /bin/sh
echo "Content-type: text/plain";
echo;
cd "${SITE_ROOT}/var/www/html";
"${SITE_ROOT}/var/www/html/bin/example.pl";
echo "Script completed with exit code $?.";
exit 0;

Once you have created this file, upload it to '/var/www/cgi-bin'. (Make sure to set the permissions to 755.) When you have completed this, test the script by going to 'http://domain.com/cgi-bin/web.sh' (substituting your domain name for domain.com). If you did everything properly, you will see a page and the last line (possibly the only line) says: Script completed with exit code 0. The '0' may be some other number depending on what example.pl does, but '0' is the most typical.

Q. Why can't I have a cron job run more frequently than once per hour? I have a script that needs to be run every 5 minutes!
A. Because your site is on a server that is hosting many other websites, we can't allow any one site to create too much load on the server. If you need more control over you cron jobs, you might consider switching over to our (dv) Dedicated Virtual Server product line where you can have complete control over your server including root level access.

Revisions:

07-20-2009: Minor Fixes
 


User Comments

No visitor comments posted. Post a comment

Fields marked with an asterisk(*) are required. Comment on this article

Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue