V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
binghe
V2EX  ›  Linux

centos 计划任务不执行

  •  
  •   binghe · 2015-01-25 00:17:29 +08:00 · 4628 次点击
    这是一个创建于 3394 天前的主题,其中的信息可能已经有所发展或是发生改变。
    请求帮助,嗯,先看图。图下面还有说明

    


    目录结构如上图。
    手工执行
    python ./baidu/auto.py
    或者
    /usr/bin/python python ./baidu/auto.py

    都能执行脚本。但是就是不能执行计划任务。
    每次编辑/添加任务时,都有执行一下service crond restart 都提示OK。
    18 条回复    2015-01-25 09:43:44 +08:00
    cevincheung
        1
    cevincheung  
       2015-01-25 00:19:12 +08:00   ❤️ 1
    请使用绝对路径……
    cevincheung
        2
    cevincheung  
       2015-01-25 00:19:36 +08:00   ❤️ 1
    还有看cron log
    binghe
        3
    binghe  
    OP
       2015-01-25 00:20:00 +08:00
    @cevincheung 刚刚接触linux,不知道绝对路径怎么写。。囧~~
    binghe
        4
    binghe  
    OP
       2015-01-25 00:21:04 +08:00
    @cevincheung log也看不懂。。。。

    Jan 24 10:22:01 default CROND[6050]: (root) CMD (run-parts /etc/cron.hourly)
    Jan 24 10:27:46 default crontab[6089]: (root) LIST (root)
    Jan 24 11:00:01 default CROND[6094]: (root) CMD (/usr/bin/python python ./baidu/auto.py)
    Jan 24 11:00:01 default CROND[6095]: (root) CMD (/usr/bin/python python ./baidu/auto.py)
    Jan 24 11:01:01 default CROND[6099]: (root) CMD (/usr/bin/python python ~/baidu/auto.py)
    Jan 24 11:03:12 default crond[6120]: (CRON) STARTUP (1.4.4)
    Jan 24 11:03:12 default crond[6120]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 16% if used.)
    Jan 24 11:03:12 default crond[6120]: (CRON) INFO (running with inotify support)
    Jan 24 11:03:12 default crond[6120]: (CRON) INFO (@reboot jobs will be run at computer's startup.)
    Jan 24 11:05:01 default CROND[6124]: (root) CMD (/usr/bin/python python ~/baidu/auto.py)
    Tomilay
        5
    Tomilay  
       2015-01-25 00:22:14 +08:00   ❤️ 1
    @binghe 就是脚本的完整路径啊 比如 /root/baidu/auto.py
    endoffight
        6
    endoffight  
       2015-01-25 00:25:30 +08:00 via Android   ❤️ 1
    加上>/tmp/baidu.log看看日志
    binghe
        7
    binghe  
    OP
       2015-01-25 00:37:35 +08:00
    @Tomilay 改成
    35 0 * * * /usr/bin/python python /root/baidu/auto.py
    还是没执行。


    @endoffight
    35 0 * * * /usr/bin/python python /root/baidu/auto.py >/tmp/baidu.log
    这样吗?
    9hills
        8
    9hills  
       2015-01-25 00:40:28 +08:00   ❤️ 1
    @binghe 把中间的那个python给去了。。

    35 0 * * * /usr/bin/python /root/baidu/auto.py >/tmp/baidu.log
    9hills
        9
    9hills  
       2015-01-25 00:41:03 +08:00   ❤️ 1
    @binghe 所有crontab命令必须本地测试过。。你用
    /usr/bin/python python /root/baidu/auto.py >/tmp/baidu.log

    我就不信你本地能跑通。。。
    binghe
        10
    binghe  
    OP
       2015-01-25 00:45:02 +08:00
    @9hills 刚开始折腾环境时是先在本地vm里面试一遍的,后来弄这个脚本时偷懒了。。没本地测试。
    scarlex
        11
    scarlex  
       2015-01-25 00:45:46 +08:00   ❤️ 1
    注意下系统的时区
    binghe
        12
    binghe  
    OP
       2015-01-25 00:48:30 +08:00
    @9hills 还真是中间多了那个Python的问题。刚刚去掉就能执行了。。

    45 0 * * * /usr/bin/python /root/baidu/auto.py


    多谢楼上各位了。因为我一开始手工运行时是
    Python ./baidu/auto.py
    或者
    Python ~/baidu/auto.py
    所以以为编辑任务时没有用绝对路径,而且以为也要加上Python。。。。
    binghe
        13
    binghe  
    OP
       2015-01-25 00:50:26 +08:00
    @scarlex 一开始是时区问题,后来改回来了,然后遇到上面的问题卡壳了,,这东西还是得有人教学的快啊。
    vimutt
        14
    vimutt  
       2015-01-25 01:14:29 +08:00   ❤️ 1
    现在 crontab文件里最后一行有详细的说明的 对应每一个字段
    ljcarsenal
        15
    ljcarsenal  
       2015-01-25 02:07:26 +08:00   ❤️ 1
    好奇这脚本是干啥的
    binghe
        16
    binghe  
    OP
       2015-01-25 02:20:33 +08:00
    @vimutt 新手新手,谅解一下哈。。。哈哈。。。


    @ljcarsenal 额,这东西就是百毒贴吧自动签到的。
    Livid
        17
    Livid  
    MOD
       2015-01-25 07:38:06 +08:00   ❤️ 1
    0 * * * * cd /root/baidu && python auto.py > /dev/null
    decken
        18
    decken  
       2015-01-25 09:43:44 +08:00   ❤️ 1
    刚好遇到这个问题, 除了命令正确之外 还需注意时区问题, 更改了时区之后不要忘记了重启crond
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3629 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.