通过cron(python m)将库模块作为脚本运行

2024-04-16 09:20:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了python库。为了避免安装可执行的python脚本,我允许库模块作为可执行文件工作。可以使用-m opion(python-m)将模块作为脚本运行。 手动操作一切正常:

$ python -m Library.Core.Runner runFirst

但当我试图用cron运行这个程序时,它不起作用:

^{pr2}$

/var/log/cron的输出:

Jul 26 18:25:01 myhostname crond[23735]: (/usr/bin/python) ERROR (getpwnam() failed)

我怎样才能修好它?在

环境:CentOS 7,Python 2.7.5


Tags: 模块core程序脚本log可执行文件varlibrary
1条回答
网友
1楼 · 发布于 2024-04-16 09:20:59

添加用户名以让cron代表他运行任务:

*/5 * * * * <username> /usr/bin/python -m Library.Core.Runner runFirst >> /var/log/MyProject/runFirst.log 2>&1
*/5 * * * * igor /usr/bin/python -m Library.Core.Runner runFirst >> /var/log/MyProject/runFirst.log 2>&1

相关问题 更多 >