Export USER env variable for use in cron
bash, cron, ubuntu
Solution
You could work around it by writing at the top of the script (Bashism):
USER=$(whoami)
or old-style:
USER=`whoami`
... assuming you have `whoami` in the `PATH`, which can also be set in the `crontab` just like several (most?) other variables. I.e. you can also set the variable in `crontab` itself (at least in Vixies `cron`) - see here for example.
Problem
I have a script that requires the env variable USER to be set. As the script is used by several users, I can't just do `export USER=xxx` at the beginning of the script. I could define in the `crontab`, but I was just wondering whether there is a good way of pulling it in. I tried sourcing `.bashrc` and `.profile`, but neither define USER, plus on Ubuntu `.bashrc` simply returns on non-interactive shells.