1

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.

What I would like to do is the following:

  • add a cron job to the cron tab

Terminal Error Output:

 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
asked Jul 1, 2015 at 22:26
1
  • 1
    You need to run it as root. Non privileged user can only work on their own crontab. Commented Jul 1, 2015 at 22:28

3 Answers 3

3
users_cron = CronTab(user='testuser')

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

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

Reference

answered Jul 1, 2015 at 22:28
Sign up to request clarification or add additional context in comments.

Comments

2

You're trying to access a specific user's crontab, you can't do that on the base system (which is what the python module is trying to use) without root access. If you want to get your own crontab do the following:

users_cron = CronTab(user=True)
answered Jul 1, 2015 at 23:13

Comments

0

You can also use plan which is an easier way to write cron job for crontab from python:

from plan import Plan
cron = Plan()
cron.command('ls /tmp', every='1.day', at='12:00')
cron.command('pwd', every='2.month')
cron.command('date', every='weekend')
if __name__ == '__main__':
 cron.run()

See more in the docs

answered Jul 1, 2015 at 23:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.