Question

I am trying to use this example script to test crontab in python:

from crontab import CronTab

tab = CronTab(user='www',fake_tab='True')
cmd = '/var/www/pjr-env/bin/python /var/www/PRJ/job.py'
cron_job = tab.new(cmd)
cron_job.minute().every(5)
#writes content to crontab
tab.write()
print tab.render()

It returns with an error 'fake_tab' not defined. If i remove this parameter and call the function
like this: CronTab(user='www'). I returns the following error :

Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
tab = CronTab(user='www')
File "C:\Python27\lib\site-packages\crontab.py", line 160, in __init__
self.read(tabfile)
File "C:\Python27\lib\site-packages\crontab.py", line 183, in read
p = sp.Popen(self._read_execute(), stdout=sp.PIPE)
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

Does any one know, what am I missing?

Was it helpful?

Solution

I think that Crontab is a Unix/Linux concept. Not sure if it can work under windows. This Page says "Windows support works for manual crontabs only". Not sure what he means by that though.

OTHER TIPS

As the author of python-crontab I can report that the documentation has been updated. It's clear ineffective given the number of people puzzled over what manual means.

If you do this:

mem_cron = CronTab(tab="""
  * * * * * command # comment
""")

You should have a memory only crontab. Same if you do a file as a crontab:

file_cron = CronTab(tabfile='filename.tab')

I'm always looking to improve the code and documentation, so please do email me.

The easiest way I found to make crontab find my job was:

In settings.py (I'm using django) I defined these variables:

CRONTAB_EXECUTABLE='C:/Users/myuser/myvirtualenv/Lib/site-packages/django_crontab/crontab.py'
CRONTAB_DJANGO_PROJECT_NAME='myproject'
CRONTAB_DJANGO_MANAGE_PATH='C:/Users/myuser/myvirtualenv/myproject/manage.py'
CRONTAB_PYTHON_EXECUTABLE='C:/Users/myuser/AppData/Local/Programs/Python/Python36-32/pythonw.exe'

Pay attention to the slash. It must be leaned to the right or it causes a syntax error.

By this way crontab will find the job or whatever you are trying to execute. In my case I was trying:

C:\Users\bsi\mlearning3\src>python manage.py crontab add
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top