September 24, 2004

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:
MTTrickle - automated posting of deferred MT Entries, for MT2.x
MT-Publish-On - Tim Appnel's code modification patches for MT2.64 to allow future posting.
ScriptyGoddess's Pre-Post script



Has this tutorial been helpful? Please consider linking to Learning Movable Type at http://learningmovabletype.com/ . Thanks!

Posted by Elise Bauer on September 24, 2004 to General Tips and Tricks, Servers
Comments(17) | Email to a friend | Printer-friendly version


Trackback

If you would like to send a trackback
please use the following URL: http://learningmovabletype.com/cgi-bin/mt32/mt-tb.cgi/348

» "./tools/run-periodic-tasks: Permission denied" error from Murdoc Online
This will probably not be news to most other bloggers out there using MoveableType 3.x, but it took me a while to figure it out so I'm posting it here in the hopes that I can help someone else stuck......[read more]

Tracked: March 13, 2005 07:43 PM

» Nice Blog For Learning Movable Type from Willie Crawford's Marketing Insights
There's a nice blog at: http://www.elise.com/mt/ where a lot of Movable Type how to is explained. For example, there's an......[read more]

Tracked: May 19, 2005 10:22 PM

» Cron Jobs and MT from Much Madness is Divinest Sense
Learning Movable Type has an interesting post about scheduled postings and cron jobs. A cron job is an automated task set to run in the future. If you have MT 3.x, you have probably noticed you can save a post......[read more]

Tracked: July 7, 2005 08:00 AM

Comments

It's worth noting that most *nix webhost control panels (at least the ones I've played with) offer some sort of interface to Cron--it's not just cPanel.

Of course, the process by which you create the cron job is the same.

Hello, I followed the instructions for setting up a cron job but the scheduled posting doesn't work. When I pointed my browser at http://www.mydomain.com/path-to-mt/tools/run-periodic-tasks,

I got a 500 Internal Server Error.

"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request."

Any idea what I should do to get the thing working?

Any help is appreciated.

Thanks :)

Thank goodness for this site. I just posted a comment with "Future" and was surprised when nothing happened.

I clicked the [?] button to show the MT documentation and saw only "Entries with Status set to Draft will not be published to your weblog".

I've been feeling that the MT documentation is a bit opaque but now this confirms it. But this site is a bit more useful :)

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?

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.

Is this process any different for servers running Ensim? My host's support staff has tried several variations of this line, and none of them has worked, always giving the MT.pm error.

when the Cron job runs, should it ALWAYS send an e-mail?

for example, when I had it configured incorrectly, I got an error message e-mailed to me. However, once I debugged it and now it's running fine, I never get the e-mail, even when it posts new entries set for "future". It runs fine, the entries post but I get no notification. Is this how the cron job is supposed to work?

So, anybody know if the post is pinged when it's set for FUTURE???

It turns out that cron posting doesn't ping. A pity, that. Here's the lowdown from MT customer support:

Currently this capability does not exist for the Scheduled Posting feature. It may be that the engineers have not completed plans for developing it fully; or it may have been merely an oversight not to have the pings sent.

There is a report on file to have this added, but it is up to the product development team to determine when it will be addressed for future versions.

It was suggested that I check the MT forums to see if anyone has devised a hack for this. If so, I'll post word of it here.

I've posted this in the MT Support forum but no one seems to be able to help.

I have the cron job set up EXACTLY as stated. I asked my ISP to confirm that it is running, and it is. I have a post set to Future with the correct formating for the date. I tried building the site as static and dynamic. NOTHING works. The cron job executes, but the posting never changes from Future to Publish, and never appears on the site.

Please help!!!!
-Jeff

My webhost doesn't have C-Panel like the above tutorial, but allows you to type in a path to a cron script. I too have had the mt.pm error.

I searched and saw some entries over at the Movable Type forums that said they put the mt.pm file in their Movable Type installation directory (mine's in my cgi-bin) and it worked. Haven't tried it yet, but I'm going to give it a shot.

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.

Can always count on you! Just wanted to say thanks - whenever I need to know how to do something with MT I can just search your site and know you will have just what I am looking for. Have set it up so should see how it works... thanks!

It runs fine, the entries post but I get no notification. Is this how the cron job is supposed to work?

Hope so. I sure wouldn't want to get an email *every* fifteen minutes. :-)


Post a comment

(Before posting a comment please see the Comments and Trackbacks Policy. Do you need help troubleshooting your weblog? Please post questions and requests for support at the MT Support Forums. Thanks!)




Remember Me?

(you may use HTML tags for style)

Email to a friend

Email this article to:


Your email address:


Message (optional):