Wednesday, July 26, 2006

Python from cron

Problem: I was getting fatal errors from my cron script (Solaris bash) that calls a Python pexpect/telnet script, all about python: fatal: libX11.so.4: open failed. Of course there's no GUI with this shell script, so X11 doesn't seem necessary.

The shell script already exported PYTHONPATH pointing to pexpect's directory, all paths were absolute, and ldd python didn't show any missing libraries. Very frustrating, because of course the scripts work when I run them from the command line.

Solution: If it works when you launch it from the command line, but it doesn't work from cron, that means cron's minimal environment is (part of) the problem! The environment variables you get in cron are HOME, LOGNAME, PATH=/usr/bin:/usr/sbin, and SHELL=/usr/bin/sh. This fix was to export LD_LIBRARY_PATH in the shell script called by cron, pointing to the directory with the python library of the fatal error, as quickly seen with ldd python. After all those conniptions, such a simple fix!

No comments:

Post a Comment