Solved How to set crontab's environment variables correctly?

Hello everyone,

I've read several times that /etc/crontab should never be edited, that crontab -e must be used instead.

So, I do not edit /etc/crontab. But I would like to know how to correctly set several environnement variables for cron. For instance, PATH and LC_TIME.

I know that a solution for PATH is to use absolute paths in the crontab. But I've noticed it can be tricky because all commands you call from inside the personnal scripts that you call in the crontab must also be called from absolute paths. Otherwise you get a script that works perfectly well from a shell but that seems to silently fail or to behave weirdly when called from cron.

Also, although I haven't tested this solution, it seems to be possible to use setenv at the beginning of the crontab line, but I would like to avoid proceeding this way, just as a matter of readability (I would like to set several environnement variables).

So, outside of these solutions, is there a correct and safe way to set the PATH for crontab?

Have a nice day,


QZ
 
Ok, I mistakenly thought these settings were reserved for the system crontab only.
So, I put this as resolved.
 
The /etc/crontab thing is more of a best practice. If you have to change the time on the default entries then it would have change. By leaving it alone and using user specific crontab(5) files it makes /etc/crontab another file that can be automatically upgraded during system upgrades.
 
Back
Top