推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
thiswind
V2EX  ›  Python

Crontab 无法正确读取 PATH 环境变量的解决办法

  •  
  •   thiswind ·
    thiswind · Sep 13, 2016 · 4514 views
    This topic created in 3675 days ago, the information mentioned may be changed or developed.

    运行这一句:

    curl -L https://git.io/vigfN | bash
    

    参考 braker-scripts/working-scripts/add_current_shell_and_path_to_crontab.sh

    13 replies  •  2016-09-14 12:37:35 +08:00
    doyel
        1
    doyel  
       Sep 13, 2016
    反正知道这毛病我所有 crontab 都直接写绝对路径。。
    thiswind
        2
    thiswind  
    OP
       Sep 13, 2016
    @doyel 绝对路径也木有用,因为它根本就不读 PATH 变量,环境变量全部都读不到。恩,不过一般很少会有需求会碰到这个坑
    doyel
        3
    doyel  
       Sep 13, 2016
    那倒是,碰到取环境变量就抓瞎了
    thiswind
        4
    thiswind  
    OP
       Sep 13, 2016
    @doyel 直接执行那句话就行了,包治百病。。。不放心的话可以看源码,就是一个 bash 脚本, github 上 fork 的,亲测有效
    ivanfjz
        5
    ivanfjz  
       Sep 13, 2016
    ubuntu 读环境变量的。 centos 不读
    lizheming
        6
    lizheming  
       Sep 13, 2016
    vim /etc/crontab
    service crontab restart
    试试... 不过保险起见还是写绝对路径吧...=。=||
    walkman660
        7
    walkman660  
       Sep 13, 2016
    不自动那就自己加载环境变量
    source /etc/profile
    cxbig
        8
    cxbig  
       Sep 13, 2016
    求稳妥,所有命令和文件用绝对路径,环境变量直接先赋值,如果比较多就放文件里提前 source 一下
    kikoroc
        9
    kikoroc  
       Sep 13, 2016
    赞同 @cxbig 的说法。
    skydiver
        10
    skydiver  
       Sep 13, 2016
    自己把 PATH 写到 crontab 里就行了。
    这脚本干的一样的事儿
    thiswind
        11
    thiswind  
    OP
       Sep 13, 2016
    @skydiver 恩,这个脚本就是干这个事情:)
    这个脚本的目的是用短域名,这样方便用手机拍照,也方便在机房手工敲
    手动写 PATH 一不小心容易错
    skydiver
        12
    skydiver  
       Sep 13, 2016
    @thiswind echo PATH=$PATH 然后复制粘贴就行了

    在线上机器运行来源不明的脚本是大忌
    dreamtrail
        13
    dreamtrail  
       Sep 14, 2016
    第一行加上 PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin:/sbin 就行了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2365 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 15:23 · PVG 23:23 · LAX 08:23 · JFK 11:23
    ♥ Do have faith in what you're doing.