How to get CRON to call in the correct PATHs

前端 未结 15 1223
时光取名叫无心
时光取名叫无心 2020-11-22 06:07

I\'m trying to get cron to call in the correct PATHs. When I run a Python script from shell the script runs fine as it uses the PATHs set in bashrc but when I use cron all t

15条回答
  •  半阙折子戏
    2020-11-22 06:39

    Most likely, cron is running in a very sparse environment. Check the environment variables cron is using by appending a dummy job which dumps env to a file like this:

    * * * * * env > env_dump.txt
    

    Compare that with the output of env in a normal shell session.

    You can prepend your own environment variables to the local crontab by defining them at the top of your crontab.

    Here's a quick fix to prepend $PATH to the current crontab:

    # echo PATH=$PATH > tmp.cron
    # echo >> tmp.cron
    # crontab -l >> tmp.cron
    # crontab tmp.cron
    

    The resulting crontab will look similar to chrissygormley's answer, with PATH defined before the crontab rules.

提交回复
热议问题