运行Python的Crontab问题 [英] Crontab Issues running Python

查看:108
本文介绍了运行Python的Crontab问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让cron每10分钟运行一次此命令;

I'm trying to get cron to run this command every 10 minutes;

(在/ home / pi / myst-myst / DIR中)

(In /home/pi/myst-myst/ DIR)

python myst.py `./monitor.sh`

我已经做了很多尝试来使它工作,但是cron无法正确执行它。这是我目前的情况;

I've tried pretty much everything to get it to work but cron won't execute it properly. Here is what I have at the moment;

*/1 * * * * /usr/bin/python /home/pi/myst-myst/myst.py `./monitor.sh`

任何帮助将不胜感激

我可以使用crontab的替代方法吗?我可以使用bash脚本执行python,然后对该cash脚本使用cron吗?

推荐答案

我在直接从cron调用python和perl时遇到了问题。对于perl,它归结为LIBPATH,默认情况下它不足以解决问题。

I've had problems calling both python and perl directly from cron. For perl it boiled down to LIBPATH defaulting to something insufficient.

我建议将命令包装在shell脚本中,并添加 set -x以跟踪问题

I'd suggest wrapping your commands in a shell script and adding "set -x" to trace through the problem

#!/bin/sh
set -x
export PYTHONPATH=/my/python/modules:$PYTHONPATH
/usr/bin/python /home/pi/myst-myst/myst.py $(/home/pi/myst-myst/monitor.sh)

直接调用它以确保其正常工作,然后尝试通过cron调用。确保同时重定向stdout和stderr以捕获任何错误消息

Call it directly to make sure it works, and then try calling via cron. Make sure to redirect both stdout and stderr to capture any error messages

 */10 * * * * /home/pi/myscript.sh > /home/pi/stdout 2> /home/pi/stderr

这篇关于运行Python的Crontab问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆