crontab-ui
crontab-ui copied to clipboard
ENVS are not set
The "Environment Variables:" box seems to be non functional on the latest docker image. Variables are not set and inaccessible by jobs.
Regardless of the format inputted in such box, eg:
KEY=value
Or the "wrong" for a crontab file format:
export KEY=value
When executing a simple job like the command "env", the variables are not set. Both when manually executed by the UI or automatically executed by the cron daemon.
I inspected the docker image with crontab -e
and the source code and everything seems correct (https://github.com/alseambusher/crontab-ui/blob/6cf4ce4eb818d485a22b24b0e2afabb1f81eb77a/crontab.js#L92).
Does anybody else has the same behavior?
Maybe I'm missing something obvious.
Thanks, Francesco
Make sure these boxes are checked( - [x] ) before submitting an issue.
Did you click on "save to crontab"?
@alseambusher yes sure and I checked with crontab -e
in an interactive shell that the crontab has been updated (it was). Thanks!
For example:
No "foo" variable in the log.
They are not visible to env
but they exist locally. IMHO it's something related to the Busybox crond. If a value contains a "&" the parse fails and none of the envs are available as local variables.
Solution: Double quote the value, eg.:
FOO="https://xxx.ch/xxx/xxx?xxx&xxx"
Very weird, the above solution is partial as a script (for example a PHP script) will not be able to access the data using getenv()
. I discovered that a single line at the beginning of the envs:
export FOO=bar
Somehow refresh all the envs and now env
sees everything.
Solution: Add a dummy export FOO=bar
line at the beginning.
Bummer. The above works only when manually executing the task. Jobs executed automatically do not have any of the envs, regardless the export
command.
Bummer. The above works only when manually executing the task. Jobs executed automatically do not have any of the envs, regardless the
export
command.
See the Dockerfile of this project. There you can see it uses Alpine Linux as base. Alpine Linux uses BusyBox cron (whilst e.g. Debian uses Vixie cron). As explained here, the ability to declare variables at the top of crontab files differ per implementation. BusyBox does not support it. This is a problem, since the variables as defined in crontab-ui will be added to the top of the actual crontab file, which is thus not supported in this configuration.
A solution would be therefore to change the Dockerfile to use Debian or Ubuntu as base image. Note that this leads to other mandatory modifications, like changing apk to apt in the Dockerfile.
Looks like the original developer of this project didn't know these specifics and/or did not test it well. The fact that it does work when you manually run a job lies in the fact that cron is not involved in that case. Under the hood it'll just instantly declare the variables in a command and then run the given command in the same shell.
I've got a better solution than changing the base image. Why not just fix it by modifying crontab-ui's code?
In https://github.com/alseambusher/crontab-ui/blob/master/crontab.js change line 183 from crontab_string += make_command(tab)
to crontab_string += add_env_vars(exports.get_env(), make_command(tab))
, then remove line 175 up and until 178.
This will result in the crontab file not having the top lines defining variables (which is not working in BusyBox), but rather embedding the variables into the commands to be executed themselves, just like how it is done when executing a job manually.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.