« Creating a Horizontal Navigation Bar | Main | Adding a Sidebar - MT3.1 and Earlier »

Scheduled Postings and Cron Jobs

Co-authored by Elise Bauer and Arvind Satyanarayan.
Tutorial cross posted on Movalog and Learning Movable Type

Future posting is a convenient new feature in MT3.1x, allowing you to create an entry and have it automatically post at a future time. But before you can use this feature you need to set up a Cron Job on your server.

What is a Cron Job?

Cron is a task scheduler for unix servers. A cron job is a specific task that runs a certain number of times per minute, day, week, or month on your server. For example, you can use a cron job to automate a daily MySQL database backup. The main problem with cron jobs is that if they aren't properly configured they can cause high server loads which may result in suspension of your site with your web host. If you are able, configure your cron job so that the results of running the scheduled script are emailed to you.

There are two main ways by which you create a cron job on your server: cPanel, and using shell access to your server. Cpanel is the easiest way; shell access requires knowledge of UNIX editing commands and should only be attempted by those familiar with such commands.

Using cPanel

If your webhost has cPanel installed, search for the cron command in cPanel. You may be presented with a page where you select your experience level - standard or advanced. Presented are instructions for both.

Standard

Using the standard function in cPanel, the cron job editing screen should look something like this:

Cronstandard_1 (click to view)

Your email needs to go in the textbox at the top of the screen so that the results of running the script are emailed to you. The command to be run is

cd <path to mt>; ./tools/run-periodic-tasks


Substitute <path to mt> with the path to your MT cgi files.

For example, if your MT installation is in your cgi bin, it might look like this:

cd /home/username/cgi-bin/; ./tools/run-periodic-tasks


If your MT installation is in your public_html directory, it could look like this:

cd /home/username/public_html/path/to/mt/; ./tools/run-periodic-tasks


It should be set to run every 15 minutes of every hour, every day, every weekday and every month.

Advanced

Using the Advanced function in cPanel, you will be presented with a different screen. Fill it out as shown below:

Cronadvanced_2 (click to view)

Substitute "arvinds" with your email at the top. The cron should be set to run
*/15 * * * * (every fifteen minutes of every hour of every day, every weekday, every month). The command to be run is

cd <path to mt>; ./tools/run-periodic-tasks


Using Shell Access

The Shell Access method is explained in the MT Manual. At the time of this writing, although the steps outlined in the manual are correct, the crontab command is not.

1. Log into your server.

2. Get into your crontab editor

crontab -e


3. Add the following command:

0,15,30,45 * * * * cd <path to mt>; ./tools/run-periodic-tasks


Where your path to mt is your specific path to your MT files.

This command instructs cron to run the script every 15 minutes of every hour of every day. Make sure this command is exactly as written.

Troubleshooting

There have been many errors experienced during setting this up. The first being an MT.pm error. At the time of writing this tutorial, the documentation was incorrect as the command to be run was not correct. Make sure you use the command to run as shown in this tutorial.

If you get a permission denied error make sure the run-periodic-tasks script has 755 permissions (the same permissions as all the cgi files)

If you get the error message:

You have scheduled posts but have not entered a Remote Services username in your profile, or you don't have a Movable Type proof-of-purchase. You need to do so before scheduled posts will be released.

This is a weird bug in MT at the moment. This error message does not affect anything. You can ignore it.

Scheduling Posts

With the cron job set up you are now ready to schedule your weblog posts. On the Edit Entry page of the entry that you would like to schedule for a future posting, scroll down to the bottom of the page to where you see "Post Status".

post_schedule.gif

You can now select "draft", "publish", or "future". Select "future" and adjust the date and time for the date and time that you want the post published.

Links:


Comments (6)

Waveflux Author Profile Page:

Elise, I tried out the scheduled posting feature a couple of times and found that no pings were sent out to the URLs I'd included in the entries. Have you run into this?

kgs Author Profile Page:

O.k., this question may be WAY stupid... I've been staring at variations of this cron job for far too long. (Two days!) When you say path to MT, do you mean including the MT installation directory? In other words, I have MT installed in a directory below one we'll call somedirectory. So I assume you mean:

cd /home/username/somedirectory/mt/; ./tools/run-periodic-tasks

Waveflux - I haven't run into that problem, you may want to ask over at the forums.

KGS - the example you just gave would be correct. The path is to where the mt.cgi file resides.

laanba:

Please pardon the stupid question. I'm trying to set this up and I received the permission denied error. I see that you say to check that run-periodic-tasks script has 755 permissions. Where exactly do I go to do this?

Laanba, see the LMT FTP, File Formats, and Permissions tutorial.

laanba: It wasn't obvious to me either, and I don't see where anyone has really said that there's a 'run-periodic-tasks.cgi' in the 'tools' folder of MT that needs permissions set to 755. Did the trick for me.

Post a comment

(If you haven't left a comment here before, your comment may need to be approved before will appear on the entry. Thanks for waiting.)