Planet, Shell Scripts, and Binary Locations

I ran into some issues in the last week or so with getting my Planet-updating shell script invoked by CRON; it would run when I ran the script by hand, but it wouldn’t run when cPanel’s CRON spooler would try to invoke it. I was getting the following error:

Traceback (most recent call last):
File “./”, line 23, in ?
import planet
File “./planet/”, line 23, in ?
from planet.truncate import _TruncateHTMLProcessor
File “./planet/”, line 2, in ?
import textwrap
ImportError: No module named textwrap

After looking confused for a while, I talked to my local python guru, Stephen Granade, and he pointed something out to me: is a Python 2.3-era addition, so I probably had a Python environment issue. [My server has 2.2.x and 2.4.x installed. Silly cPanel.]

Armed with this knowledge, I futzed around for a while and figured out that my shell script was missing an invocation of the Python environment. I have updated it:

#!/bin/csh -f
cd /home/path/to/planet
/path/to/python/binary ./ ./config.ini

Consult your system adminstrator if you don’t know /path/to/python/binary. If you’re the sysadmin and can’t find the Python binary, please ram your forehead into your desk repeatedly.

Thanks again, Stephen. I owe you a beer.

Shell Script for PlanetPlanet CRON Job

Has Sam Ruby gotten you excited about PlanetPlanet, even though you don’t know Python from Perl? Got it running, but don’t have a clue how to get CRON up and running with a shell script? Yeah, that was me yesterday. Google provided some help, eventually, but I’ll break it down a little more for you:

  1. Make sure all your file permissions are right. Half of my hell yesterday was having done all the work as root but not having CHOWN’d and CHGRP’d as appropriate.
  2. Use your shell script to change to the appopriate directory before invoking I’d never really had to do that, as I’m still a babe in the shell-scripting woods. But if you go in, cd to the /path/to/your/, then invoke ./ /path/relative/to/config.ini, you’ll be rockin’.

My shell script looks like:

#!/bin/csh -f
cd /home/path/to/planet
/path/to/python/binary ./ ./config.ini

Now, I simplified things by putting config.ini and in the same folder. If you didn’t [for example, if you’re using examples/basic/config.ini just for funsies], you’d just invoke ./ ./path/examples/basic/config.ini.

Thanks, Sam, for pushing me over the edge to play with PlanetPlanet. Now it’s time to get the templates like I want them so I can start using it in production. 🙂