I don't think you can do this in the crontab directly. The crontab file isn't a shell script so trying to source a script containing envvars into it doesn't work
crontab won't install this as it's not valid
crontab: installing new crontab
"/tmp/crontab.iZqWJX/crontab":1: bad minute
errors in crontab file, can't install.
What you could try is sourcing a script containing your envvars immediately before you run our job
* * * * * . /path/to/envars ; /path/to/your/job
I tested this with
* * * * * . /home/iain/envvars ; echo $HELLO >/tmp/test.out
with the envvars file containing
the file /tmp/test.out contained the following
So I guess that worked. The
source command (a synonym for
. ) is a bash builtin but source is not posix so using
. is preferred.
source: source filename [arguments]
Execute commands from a file in the current shell.
Read and execute commands from FILENAME in the current shell. The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read