I have a minimum example of my problem, which is trying to install a crontab that looks like this:
FOO="foo\"bar\"bin"
0 0 1 * * ls
by running crontab crontab
(I have it in a file name crontab
). It fails with this error:
% crontab crontab
"crontab":0: bad minute
crontab: errors in crontab file, can't install
It's the escaped quote, \"
, causing the problem.
How do I escape quotes in crontab's environment variables.
To add a bit more context, I'm not just writing variables in a manually written crontab. This crontab is generated by whenever (a Ruby gem), it has about 70 entries in them, and it picks up all environment variables and puts them as variables in the crontab so all credentials are available to the scripts. The problem is that recently I added a complex one that has quotes in it, and that broke this system.
In case you are curious, the Ruby code that generates the variables is:
ENV.each do |key, value|
env key.to_sym, value.inspect
end