Perl, FreeTDS and Cron issues


While converting some dodgy nagios-commands into cron scripts today, I came across an age-old issue when scheduling the final script in cron: The script works perfectly when running it on the command-line, but fails miserably when cron runs it.

The usual answer here is “Check the environment variables”.

The error I was getting was from perl’s DBD library when trying to connect to the MSSQL database:

failed: (DBD: dbd_db_login/SQLSetConnectOption err=-2)

Hunting around I wasn’t 100% sure what environment variables I needed.
Turns out we’re using FreeTDS to get Linux to talk to an MSSQL server.

I tried several of the environment variables I found in my shell’s environment, and a mix of several, and as it turns out I was missing only one:

PERL_DL_NONLAZY=1

Seems the previous Windows Admin Guy came across the same problem, didn’t document it anywhere, but did add the variable to the Linux machine’s global profile. This worked while Nagios was calling the perl-script, but cron runs with a nice clean environment, so didn’t help there.
So just export the PERL_DL_NONLAZY variable before you run your perl-script, and voila, there it is.

, , , ,

  1. No comments yet.
(will not be published)

  1. No trackbacks yet.