How to get CRON to call in the correct PATHs

前端 未结 15 980
时光取名叫无心
时光取名叫无心 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:42

    You should put full paths in your crontab. That's the safest option.
    If you don't want to do that you can put a wrapper script around your programs, and set the PATH in there.

    e.g.

    01 01 * * * command
    

    becomes:

    01 01 * * * /full/path/to/command
    

    Also anything called from cron should be be very careful about the programs it runs, and probably set its own choice for the PATH variable.

    EDIT:

    If you don't know where the command is that you want execute which from your shell and it'll tell you the path.

    EDIT2:

    So once your program is running, the first thing it should do is set PATH and any other required variable (e.g. LD_LIBRARY_PATH) to the values that are required for the script to run.
    Basically instead of thinking how to modify the cron environment to make it more suitable for your program/script - make your script handle the environment it's given, by setting an appropriate one when it starts.

提交回复
热议问题