I am trying to add a line to my system user's crontab, from a Python script which uses the package python-crontab. My crontab file does not exist yet, and when I run this code, nothing happens (no errors, no results, no creation of crontab file):
from crontab import CronTab
cron = CronTab(user=True)
# cron = CronTab(user='my_user') I tried this line too without any results
job = cron.new(command='python3 /opt/my_script.py')
job.minute.on(2)
job.hour.on(12)
True == job.is_valid()
Am I missing anything?
True == job.is_valid()does nothing. You should useassert job.is_valid()