0

I'm trying to run a cron job for a simple python script that will output the current time and date into a txt file.

The writedate script works fine but the cron job can't pickup the file writeDate.py no matter what path I specify.

I've tried running the file directly from the path that I put into the cron job and it works absolutely fine but it just can't find the file for some reason when I try to locate it in the cronjob script.

This is the scheduleCron.py code:

from crontab import CronTab
my_cron = CronTab(user='user')
filepath = 'C:\\Users\\user\\Downloads\\Python-Projects\\writeDate.py'
job = my_cron.new(command='python '+filepath)
job.minute.every(1)

my_cron.write()

It gives me the error [WinError 2] The system cannot find the file specified

For clarity i'm using this example - https://code.tutsplus.com/tutorials/managing-cron-jobs-using-python--cms-28231

I've also tried, in Python, printing that path and it loads the file correctly but for some reason the cron script doesn't detect it.

1
  • Just added a link to the tutorial i'm trying to follow, i'm honestly a complete newbie to cron jobs. I know it's typically done through a Unix system, but I wasn't sure if it's possible to do it through windows. Commented Jun 3, 2019 at 11:25

2 Answers 2

1

https://pypi.org/project/python-crontab/
In the end of the documents

Windows support works for non-system crontabs only. ( see mem_cron and file_cron examples above for usage )

Crontab module for reading and writing crontab files and accessing the system cron automatically and simply using a direct API.
As far as I know,only Linux or Unix like system has the crontab command.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using windows, then you can start the in-built scheduler. But you should save the cron to a file first. `cron.write('C:\SomeFile.cron') and then read it back when you need to run the scheduler. The docs explain how you can loop through the scheduler to keep it running and checking for new jobs. Make sure to use time.sleep to not lock up the process.

Comments

Your Answer

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.