【发布时间】:2016-09-20 16:32:25
【问题描述】:
我的 crontab 中有一份工作,每分钟运行一个脚本 (/home/sys_bio/username/tracer.sh)。该脚本包含
#!/usr/bin/env bash
echo "starting"
/home/sys_bio/username/p35/bin/python3.5 -m qefunctional.qe.tests.prodprobe -p post -j test.json
echo "finised"
当我在目录/home/sys_bio/username/ 中运行commany ./tracer.sh 时,它会按预期运行。
但是,当我将作业添加到 crontab 时,只有 echo 部分运行。
另外需要注意的是p35 是我的python3 所在的位置。所以/home/sys_bio/username/p35/bin/python3.5 是我运行所有python3 脚本的方式。
这就是我的 crontab 中的内容
* * * * * /home/sys_bio/username/tracer.sh >> /home/username/tracer.cron.txt
我正在创建 .txt 文件,但只保存了 echo 语句。
这可能看起来令人困惑,但目录结构是这样的:
/home
/sys_bio
/username
/qefunctional
__init__.py
/qe
__init__.py
/tests
__init__.py
prodprobe.py
test.json
/p35
/bin
python3.5
tracer.sh
/username
tracer.cron.txt
* 编辑 *
我可以在脚本中添加更多内容,以便将错误重定向到文件。脚本现在看起来像这样,我收到了这个错误:
/home/sys_bio/username/p35/bin/python3.5: Error while finding spec for 'qefunctional.qe.tests.prodprobe' (<class 'ImportError'>: No module named 'qefunctional')
脚本:
#!/usr/bin/env bash
echo "Starting Tracer POST"
/home/sys_bio/username/p35/bin/python3.5 -m qefunctional.qe.tests.prodprobe -p post -j /home/sys_bio/username/test.json -d -v 2>/home/username/crontab.output
echo "Ending Tracer POST"
【问题讨论】:
-
尝试使用
test.json的绝对路径而不是相对路径...