Search code examples
bashcronenv

How to pass all bash env variables to cron


A given crontab entry gives errors and the reason is that it can not read all env variables from bash. I wonder how could I pass all this info to cron


Solution

  • One trick I've used in the past is to open up a bash session for the specific user and just type:

    env >$HOME/.cronenv
    

    You can this source this file from your cron scripts (or directly from the crontabs if you're running an executable you can't change) with something like:

    . $HOME/.cronenv
    

    This is, of course, using a thermonuclear warhead to kill a fly. You should really identify the bare minimum that your script requires and just use that.