Answer the question
In order to leave comments, you need to log in
How to disable/enable cron tasks using python?
Good afternoon, the situation is as follows: there is a web application on flask for adding phone numbers to the database. There are scripts in cron that send SMS to numbers from the database.
0 9 * * 1 /home/xxx/yyy/mes.py -monday >> /home/xxx/dispatch.log
0 9 * * 3 /home/xxx/yyy/mes.py >> /home/xxx/dispatch.log
0 9 * * 5 /home/xxx/yyy/mes.py >> /home/xxx/dispatch.log
Answer the question
In order to leave comments, you need to log in
Write in the same line if you are confused by a bunch of unnecessary ones.
I see two solutions here.
1. Python has the ability to control the console from scripts. Separately, you write a function that will execute a request to the console. But this is an option, so-so.
2. In modern development practices, this is usually done. It's not the cron itself that starts the mailing list. And cron runs a function that will check tasks for mailing. If there are tasks, then the mailing itself is launched. What does it mean - tasks for mailing. Or you have an intermediate table where you store a list of what needs to be sent (the option is also so-so, as for me). Or at the address to store value is sent or not
Or the third variant as you offered, separately to store value true/false.
classically "truunixway" this is done via sed awk and other regexppin. it looks for a line in the file and puts a # in front of it and vice versa.
option 2: keep the contents of the crontab in the database and, with each change, completely generate /etc/crontab with the necessary included tasks
option 3: put the rules into separate files in the etc/cron.d/ directory and move them to another directory to delete them and back.
minus: support for cron.d is not available everywhere.
option 4: if there is a systemd, then use systemd.timer, where the desired functions are already built into the system.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question