I would like to ask for help with the python-crontab module. I have a simple shell script to record an internet radio stream using the curl command. I want to schedule recordings ahead by scheduling them in a crontab. I found the python-crontab module that alows me to write directly to crontab. But each time I schedule a new recording the older crontab entry is over-written. Is it possible to write persistant crontab entries using the python-crontab?
I simplified my code to demonstrate my problem:
from crontab import CronTab
def get_recording_parameters(Min,Hour,day,month,job_number):
radio_cron = CronTab()
cmd = "sh /home/pifik/Documents/record_radio.sh"
cron_job = radio_cron.new(cmd, comment='job_'+str(job_number))
cron_job.setall(Min, Hour, day, month, None)
radio_cron.write()
If I run it with the following parameters: get_recording_parameters(0,22,23,12,1), and check the crontab in Terminal with the crontab -l command I get 0 22 23 12 * sh /home/pifik/Documents/record_radio.sh # job_1. If I run it again with different parameters, for example: get_recording_parameters(10,23,25,12,2) and check the crontab with crontab -l I get 10 23 25 12 * sh /home/pifik/Documents/record_radio.sh # job_2, the job 1 is overwritten.
I tried to change the 3rd line of code to radio_cron = CronTab(tabfile='/home/pifik/Documents/filename.tab') and it helps that all new entries are appended in the filename.tab but nothing is written to the crontab. I am running Ubuntu 14.04 and Python 3.4.3.