centos 计划任务不执行

2015-01-25 00:17:29 +08:00
 binghe
请求帮助,嗯,先看图。图下面还有说明





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

都能执行脚本。但是就是不能执行计划任务。
每次编辑/添加任务时,都有执行一下service crond restart 都提示OK。
4636 次点击
所在节点    Linux
18 条回复
cevincheung
2015-01-25 00:19:12 +08:00
请使用绝对路径……
cevincheung
2015-01-25 00:19:36 +08:00
还有看cron log
binghe
2015-01-25 00:20:00 +08:00
@cevincheung 刚刚接触linux,不知道绝对路径怎么写。。囧~~
binghe
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
2015-01-25 00:22:14 +08:00
@binghe 就是脚本的完整路径啊 比如 /root/baidu/auto.py
endoffight
2015-01-25 00:25:30 +08:00
加上>/tmp/baidu.log看看日志
binghe
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
2015-01-25 00:40:28 +08:00
@binghe 把中间的那个python给去了。。

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

我就不信你本地能跑通。。。
binghe
2015-01-25 00:45:02 +08:00
@9hills 刚开始折腾环境时是先在本地vm里面试一遍的,后来弄这个脚本时偷懒了。。没本地测试。
scarlex
2015-01-25 00:45:46 +08:00
注意下系统的时区
binghe
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
2015-01-25 00:50:26 +08:00
@scarlex 一开始是时区问题,后来改回来了,然后遇到上面的问题卡壳了,,这东西还是得有人教学的快啊。
vimutt
2015-01-25 01:14:29 +08:00
现在 crontab文件里最后一行有详细的说明的 对应每一个字段
ljcarsenal
2015-01-25 02:07:26 +08:00
好奇这脚本是干啥的
binghe
2015-01-25 02:20:33 +08:00
@vimutt 新手新手,谅解一下哈。。。哈哈。。。


@ljcarsenal 额,这东西就是百毒贴吧自动签到的。
Livid
2015-01-25 07:38:06 +08:00
0 * * * * cd /root/baidu && python auto.py > /dev/null
decken
2015-01-25 09:43:44 +08:00
刚好遇到这个问题, 除了命令正确之外 还需注意时区问题, 更改了时区之后不要忘记了重启crond

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/165168

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX