python-使用crontab [英] python - working with crontab

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

问题描述

我是python的新手。谷歌搜索使我进入了这个模块 https://pypi.python.org/pypi/python-crontab 。我已经设置好环境并安装了python-crontab == 1.9.3。但是我不断出错。我究竟做错了什么?任何帮助将不胜感激。我正在尝试使用示例,但它们似乎对我没有帮助。

I'm fairly new to python. Some googling has got me to this module https://pypi.python.org/pypi/python-crontab. I've setup my env and installed python-crontab==1.9.3. But I keep getting errors. What am I doing wrong? Any help would be greatly appreciate. I'm trying to use examples but they don't seem to be working for me.

我想做的是以下事情:


  • 将cron作业添加到cron选项卡

终端错误输出:

    Traceback (most recent call last):
      File "test5.py", line 5, in <module>
        users_cron    = CronTab(user='testuser')
      File "/Users/testuser/Desktop/sample1/prj-env/lib/python2.7/site-packages/crontab.py", line 187, in __init__
        self.read(tabfile)
      File "/Users/testuser/Desktop/sample1/prj-env/lib/python2.7/site-packages/crontab.py", line 231, in read
        raise IOError("Read crontab %s: %s" % (self.user, err))
    IOError: Read crontab testuser: crontab: must be privileged to use -u


推荐答案

users_cron    = CronTab(user='testuser')

似乎您正在尝试为用户 testuser创建cronjob。

It appears like you are trying to create a cronjob for the user 'testuser'.

IOError: Read crontab testuser: crontab: must be privileged to use -u

该错误告诉您您必须是特权用户才能执行此操作。尝试使用'sudo'运行脚本:

The error is telling you that you need to be a privileged user to be able to do that. Try running your script with 'sudo':

sudo python my_python_script.py

参考

这篇关于python-使用crontab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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