I need to run a cron job daily, weekly, monthly using python. I did much research and decided to go with crontab. This is my configuration :
"schedule" : {
"name": "xyz",
"at": "12:00:00 AM",
"every": "1d"
}
Here, every can take the value of 1d, 1w, 1m for daily, weekly, monthly. It can also take values as 2d, 2w, 2m, etc. I have identified the code for daily and monthly. I am stuck with weekly. Can anyone help ?
my_cron = CronTab(user=self.user)
for job in my_cron :
if job.comment == self.name:
my_cron .remove(job)
my_cron .write()
job = my_cron .new(
command='sh start.sh "invoke-adapter"',
comment=self.name)
job.setall(str_job_schedule)
vmware_cron.write()
For monthly, str_job_schedule = "30 03 * */1 *" (runs every month)
For daily, str_job_schedule = "30 03 * * */1" (runs every day)
For weekly, str_job_schedule = "30 03 ? * *"