I have a script that works perfectly if I execute it from the command line manually. However, when it runs via cron, the job fails with the following error:

/usr/bin/env: escript: No such file or directory

The first line in the script is:

#!/usr/bin/env escript

The only thing I can figure is that escript is not being found, and that is because it is not installed in /usr/bin, but in a sub-directory of the user's home directory.

My understanding--perhaps misunderstanding--of cron is that cron runs each job in a user's crontab under the UID/GID of the user. Should it also not inherit the PATH variable from the user as well? Must everything be specified as absolute paths?

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

Cron runs under the UID of the user but with a minimal PATH. Your script needs to use a full path to the interpreter (escript) or you need to set the PATH in the crontab.

link|improve this answer
feedback

cron does not inherit the PATH from the users's interactive setup. PATH is set to "/usr/bin:/bin"

Ypu can set environment variables on the crontab line

See man crontab for the details e.g. man crontab

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.