简体   繁体   English

使用python包entry_point名称运行cron任务

[英]Run cron task with python package entry_point name

Is there any way to run cron task with python package name (specified the in entry_point)? 有什么办法可以使用python包名称(在entry_point中指定)运行cron任务?

setup.py setup.py

from setuptools import setup 从setuptools导入设置

from setuptools import setup

setup(
    name='myapp-cli',
    (..blah..)
    packages=[
        'myapp_cli'
    ],
    install_requires=['configparser', 'requests'],
    entry_points={
        'console_scripts': [
              'myapp= myapp_cli.main:cli'
          ]
    },
    zip_safe=True
)

It works in shell: 它在外壳中工作:

myapp do_stuff

I want to run app by name in cron task like this: 我想在cron任务中按名称运行应用,如下所示:

* * * * * /something_here? myapp do_stuff >> myapp.log 2>&1

I can't figure out how python packages entry_point works and how to use it in cron. 我不知道python包entry_point的工作方式以及如何在cron中使用它。 Is it possible? 可能吗?

This is not a Python issue, but linux / shell. 这不是Python问题,而是linux / shell。

The easiest way to fix it may be to use absolute paths, for Python and your script. 解决该问题的最简单方法可能是使用绝对路径(适用于Python和您的脚本)。

Assuming your entry point is located at /usr/sbin/myapp (you should find it with which myapp ) 假设您的入口点位于/usr/sbin/myapp (您应该在which myapp找到which myapp

* * * * * /usr/bin/env python /usr/sbin/myapp do_stuff >> myapp.log 2>&1

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

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