Where can I set environment variables that crontab will use?

后端 未结 17 1849
说谎
说谎 2020-11-22 05:47

I have a crontab running every hour. The user running it has environment variabless in the .bash_profile that work when the user runs the job from the terminal,

17条回答
  •  庸人自扰
    2020-11-22 06:06

    • Set Globally env
    sudo sh -c "echo MY_GLOBAL_ENV_TO_MY_CURRENT_DIR=$(pwd)" >> /etc/environment"
    
    • Add scheduled job to start a script
    crontab -e
    
      */5 * * * * sh -c "$MY_GLOBAL_ENV_TO_MY_CURRENT_DIR/start.sh"
    

    =)

提交回复
热议问题