10

I'm fairly new to python and I'm trying to create a cronjob through a python script but I keep getting an error. Any help would be greatly appreciated it to show me what I'm doing wrong?

thanks

python script

from crontab import CronTab
cron = CronTab(user=True)
job = cron.new(command='python /Users/<useraccount>/Desktop/my_script.py')
job.minute.on(2)
job.hour.on(12)
cron.write()

Errors:

Traceback (most recent call last):
 File "/Users/<useraccount>/Desktop/01-python-crontab.py", line 3, in <module>
 cron = CronTab(user=True)
TypeError: __init__() got an unexpected keyword argument 'user'
asked Jul 16, 2015 at 6:13
1
  • It looks like giving the user=True argument isn't valid. Have you looked at the documentation for the crontab module? Commented Jul 16, 2015 at 6:18

2 Answers 2

7

Here was the issues:

Error showed up: TypeError: init() takes exactly 2 argument

documentaton: https://pypi.python.org/pypi/python-crontab helped to resolve the issue.

Reason: 1 - crontab was installed not python-crontab

Here's the completed code:

def main(): 
 from crontab import CronTab
 cron = CronTab(user=True)
 job = cron.new(command='python /opt/my_script.py')
 job.minute.on(2)
 job.hour.on(12)
 cron.write()
if __name__ == "__main__":
 main()
answered Jul 16, 2015 at 6:34
Sign up to request clarification or add additional context in comments.

1 Comment

This was my exact problem. Un-installing crontab then installing python-crontab fixed my issue.
2

You may be using an old version of crontab (See - Documentation for 1.4.1 here) . You can either upgrade to latest version of python-crontab using -

pip install python-crontab --upgrade

Or download the 1.9.3 version from here and install it.

If you want to use the old version, you can pass in the username as the argument, Example -

cron = CronTab('<username>')
answered Jul 16, 2015 at 6:34

1 Comment

I was using crontab-0.21.3 instead of python-crontab. Had to 'pip uninstall crontab' and then install the new version. Thanks.

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.