• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

How do I schedule a cron job for Cloud Sites?


NOTE: This article is written for our First-Generation Cloud Control Panel. You can access this interface from the Next-Generation Cloud Control Panel by clicking your username in the upper-right of the control panel and selecting "First-Generation Control Panel".

Before scheduling a task, take a minute to review the five necessary components in creating a scheduled task on Cloud Sites:

1. Task Name – You will need to name each cron job you schedule. The name you choose is completely up to you and does not have any specific requirements.

2. Email Address for Output - You will need a valid email address so you can receive notice once the job has completed. You may have to tune your spam filter settings to receive the desired status emails.

3. Command Language - What language is the script to be executed written in? The Rackspace Cloud supports the scheduling of scripts which execute in the following environments:

* PHP
* Python
* Perl
* HTTP

Items to note about the scripting language options:

  • The "Perl" option can also be used to execute shell scripts.
  • The "HTTP" option causes a visit to the URL you provide (technically running "curl <URL>" for the cron task).  The output is sent to the task log in your webroot's "logs" directory.

4. Command to Run – You’ll need to indicate the path to the script that you wish to be execute.

5. Frequency / Date / Time - How frequently do you want the task to run? Everyday? Once a week? Once a week on a certain day of the week? Once a month? Once a month on a certain day of the month? What time of day do you want the specified task to run? All of these variations are possible through The Rackspace Cloud control panel.

Here’s an example of setting up a new scheduled task in The Rackspace Cloud control panel.

1. Log into the Control Panel at https://manage.rackspacecloud.com.

2. Click on "Hosting" on the left navigation menu and then click on "Cloud Sites". Click on the site you want to add a cron to.

3. Click on the "Features" tab on the top navigation bar.

3. Scroll down to the section called “Scheduled Tasks (Cron Jobs).” This is where you will see all tasks that you have scheduled and their status for that particular domain.

4. Add a new task by clicking the “Add New Task” button. (NOTE: All newly created cron jobs are enabled by default.)

5. Enter a task name. For this example, let’s call our task as “Wake Me Up.”

6. Enter the email address where you want the output from your task to be sent. For this illustration, we’ll enter sleepyuser@myhome.com.

7. The script that was chosen is written in Perl. So we’ll choose Perl as the command language.

8. Under the Command to Run option, it’s important to note that the top-level fully qualified path will be appended to the script path. Now the fully qualified path to our script is:

/mnt/Target01/123456/www.wakeupcall.com/scripts/wakemeup.pl

In this case, we would only have to enter “scripts/wakemeup.pl” in the field. “/mnt/Target01/123456/www.wakeupcall.com/” will automatically be appended. Please also note that the trailing slash is automatically added.

9. The next section involves scheduling the time when the job needs to be run. In our case, we want the script to run every day at 7:00AM. So we would change the selection under “Repeat by the: __” drop down menu to “Day.” In the “Time” field, we would enter “7:00.”

10. Click the “Add Task” button at the bottom and the cron job will be enabled.

NOTE: When you add a website through The Rackspace Cloud control panel, a log directory is also created as a part of the website directory structure. In order for the cron tool to run properly, this directory structure must be preserved.

If you have any other questions on scheduling a task, please do not hesitate to contact our support team.



© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER

8 Comments

how i can delete whole site using shell command of perl in cron
its urgent

I wouldn't recommend doing this through a cron job (deletion on that scale should likely be done manually via FTP). If you're set on it, though, note that the "perl" script type also supports shell scripts, and the "rm" command works in a shell script.

If the option to run the command with the option of NOW
or One time. It would be easier and simpler to run the one time cron jobs.

Thanks.

Thanks for the suggestions Shoaib. I'll pass the suggestion back, but you might also add a vote and comment to this suggestion on our Product Feedback Forum:

http://feedback.rackspace.com/forums/71021-product-feedback/suggestions/1100319-run-now-ability-for-cron-jobs

In our site Admin has the privilege to set cron timings (it may be daily once, twice or thrice).
Based on these settings, cron has to be scheduled.
Can you please help me....

You should be able to use the above directions to get to the cron scheduling interface - it's under the "Features" tab for your site in the Cloud Control Panel.

To get the scheduling you want, check the menu at the top of the last section, "Repeat by the". The menu gives a choice of month, day, hour, or minute. For your schedule, you could use "daily" for a task that runs just once, or you can select "Hourly" to run twice or three times a day. Just change the hourly interval for either case - every 12 hours for twice a day, every 8 hours for three times a day.

Thanks for the reply.
But my question here is i have to pick the cron timings from the database as per that time my cron should schedule.

For Example: today admin settings may be daily starting at 7:00 AM and interval of 6 hrs.
ideally this means the cron should run on 7:00Am and 1 PM, etc...

But again from the admin this may change to interval of 3 hrs.
So in this case from the next day cron should run on 7:00Am and 10:00 AM, etc...


Ah, I see. I'm afraid there isn't a way to automate the scheduling with Cloud Sites. You'd need to either find an established interval that could work consistently, or manually change the timing when needed.

One more possibility would be to set something up to run the cron job on a Cloud Server, since you would have more flexibility to run a script to retrieve the information from the database and modify the cron entry for the maintenance task.

Add new comment