Env vars with newlines cause whenever to create invalid crontabs
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 8.9k
- Forks
- 715
- PR merge metrics
- No merged PRs in 30d
Description
The title pretty much says it all. If you specify an environment variable with a newline in it (eg env('FOO', "bar\nbaz"), the resulting crontab is invalid. It puts the later lines of the environment variable on their own lines. Since baz is an invalid crontab, this produces
➜ echo "env('FOO', \"bar\\\nbaz\")" > schedule.rb
➜ whenever -f schedule.rb
FOO=bar
baz
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
Apparently this is a limitation of crontab's variables. Putting quotes around the multiline variable contents doesn't help.
My current workaround is to write the env vars to a temp file and then source it:
environment_variables = { FOO: "bar\nbaz" }
env_script_string = environment_variables.map do |key, value|
"export #{key}=\"#{value}\"\n"
end
env_script = Tempfile.new('env_script')
env_script << env_script_string
set :job_template, "bash -l -c 'source #{env_script.path}; :job'"
Is there any better way to handle this with Whenever itself?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the shown schedule.rb and whenever -f schedule.rb commands, then trace how env('FOO', "bar\nbaz") is rendered into cron syntax. Done means the behavior for multiline environment values is clearly resolved, with the generated crontab remaining valid or the limitation documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100