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 :(

aronisstav
  • 7,755
  • 5
  • 23
  • 48
Gordon Guthrie
  • 6,252
  • 2
  • 27
  • 52

3 Answers3

3

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
  • 34,891
  • 3
  • 56
  • 79
  • 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 Jan 22 '10 at 22:48
3

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
  • 34,891
  • 3
  • 56
  • 79
0

Changing #!/usr/bin/env escript to #!/usr/local/bin/escript at the top of the file will work if the Erlang versions are the same.

Aaron Lelevier
  • 19,850
  • 11
  • 76
  • 111