Where can I set environment variables that crontab will use?

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

    Expanding on @Robert Brisita has just expand , also if you don't want to set up all the variables of the profile in the script, you can select the variables to export on the top of the script

    In crontab -e file:

    SHELL=/bin/bash
    
    */1 * * * * /Path/to/script/script.sh
    

    In script.sh

    #!/bin/bash
    export JAVA_HOME=/path/to/jdk
    
    some-other-command
    

提交回复
热议问题