I am trying to modify the crontab of the root user through a script of python (main.py).
This script will open the crontab for root user and will modify it inserting a new command to call single.py with a parameter. The command used is not the problem as I have run it from the command line and it works. When I run the main.py script I can see the new entry when I run the crontab -l
command. Everything looks correct but it does not work when is the time (nothing has been executed).
Doing some checks, if I execute the crontab -e
command and I insert the command manually; when I save and close it; it shows: **crontab: installing new crontab**
and then it works.
main.py:
fname = "/var/spool/cron/crontabs/root"
f = open(fname,"w+")
f.write("24 19 16 01 * python /home/pi/single.py 2087111972\n")
f.close() # save and close cron file
BTW: As this script has to be recursive (it will call itself for rescheduling its execution by modifying the crontab), is there anyway to apply the changes on crontab through the script?