Python - crontab to run a script

I am new to python and I am trying to create a cronjob through a python script, but I keep getting the error. Any help would be greatly appreciated to show me what I am 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() 

Error:

 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' 
+5
source share
3 answers

There were problems here:

Error detected: TypeError: init () takes exactly 2 arguments

documentation: https://pypi.python.org/pypi/python-crontab helped solve the problem.

Reason: 1 - crontab installed, not python-crontab

Here is 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() 
+5
source

Perhaps you are using an old version of crontab (see "Documentation for 1.4.1 here ). You can either upgrade to the latest version of python-crontab using -

 pip install python-crontab --upgrade 

Or download version 1.9.3 from here and install it.

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

 cron = CronTab('<username>') 
+2
source

i get the error below when i start cron

 raise IOError("Please specify user or filename to write.") 

OSError: Please provide username or file name for recording. enter code here

0
source

All Articles