How to get CRON to call in the correct PATHs

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

    If you don't want to have to make the same edits in various places, then roughly do this:

    * * * * * . /home/username/.bashrc && yourcommand all of your args
    

    The . space and then the path to .bashrc and the && command are the magic there to get your environment changes into the running bash shell. Too, if you really want the shell to be bash, it is a good idea to have a line in your crontab:

    SHELL=/bin/bash
    

    Hope it helps someone!

    0 讨论(0)
  • 2020-11-22 07:04

    Setting PATH right before the command line in my crontab worked for me:

    * * * * * PATH=$PATH:/usr/local/bin:/path/to/some/thing
    
    0 讨论(0)
  • 2020-11-22 07:04

    Set the required PATH in your cron

    crontab -e
    

    Edit: Press i

    PATH=/usr/local/bin:/usr/local/:or_whatever
    
    10 * * * * your_command
    

    Save and exit :wq

    0 讨论(0)
提交回复
热议问题