Where can I set environment variables that crontab will use?

后端 未结 17 1564
说谎
说谎 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:11

    I'm using Oh-my-zsh in my macbook so I've tried many things to get the crontab task runs but finally, my solution was prepending the .zshrc before the command to run.

    */30 * * * * . $HOME/.zshrc; node /path/for/my_script.js
    

    This task runs every 30 minutes and uses .zshrc profile to execute my node command.

    Don't forget to use the dot before the $HOME var.

提交回复
热议问题