문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top