views:

55

answers:

2

I have an escript file which runs fine from the command line, i.e.:

./escript_file

It is meant to be cron friendly and all paths are explicit but when I run it, it fails to compile saying that there are bad attributes.

The bad attributes in question are macro definitions:

-define(COOKIE, 'somecookie').

The Answer

Thanks to Geoff Ready's suggestion I investigated which version of Erlang was running by printing out init:script_id() which prints out a string like {"OPT APN 181 O1", "R13B"} and, sure enough the command line and cron versions were picking up different versions.

The script had an initial line:

#!/usr/bin/env escript

and the operating system was 'finding' Erlang for me. The different environment variables of cron meant that a different erlang was being picked up (Geoff's first answer, and one I kinda knew but couldn't see how it would affect things).

The solution is then to force the version with a starting line of:

#!/usr/local/lib/erlang/erts-5.7.3/bin/escript

Postscript

There was also a different Ubuntu apt-get install of an earlier version of Erlang (in a different location to the source install) and an errant 64-bit install...

The cron environment just kept falling back to older and more obscure installs, failing all the while :(

+3  A: 

If it is working fine from the command line, a likely cause is a difference in environment variables for your interactive shell versus when cron runs the script.

Geoff Reedy
That was my first thought, it is the normal problem with cron. But it is not clear at all how the environment variables could cause a failure of the compile part of the code to execute a define which is a language construct in Erlang.
Gordon Guthrie
+2  A: 

Perhaps cron is picking up a different version of erlang in the path. Erlang R12B documentation says that escript ignores preprocessor directives besides include_lib. Erlang R13B documentation says that the preprocessor is run on the file. That would definitely explain the difference in behavior.

Geoff Reedy
Indeed we have installed R13B over R11B and escript is picking up R11B and the command line is picking up R13B
Gordon Guthrie