简体   繁体   English

由cron(python -m)作为脚本运行库模块

[英]Run library module as a script by cron (python -m)

I created python library. 我创建了python库。 In order to avoid install of executable python scripts I allowed library modules to work as executables. 为了避免安装可执行的python脚本,我允许库模块作为可执行文件工作。 It is possible to run module as script with -m opion (python -m). 可以使用-m opion(python -m)作为脚本运行模块。 Manually everything works: 手动一切正常:

$ python -m Library.Core.Runner runFirst

But when I try to run this with cron it does not work: 但是,当我尝试使用cron运行它时,它不起作用:

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

Output from /var/log/cron: / var / log / cron的输出:

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

How can I fix it? 我该如何解决?

Environment: CentOS 7, Python 2.7.5 环境:CentOS 7,Python 2.7.5

Add user name to let cron run the task on behalf of him: 添加用户名,以使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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM