To start, I cannot install new python modules and have to work with what is there already.
So I want to add or delete entries in the crontab with my python script and have to pass arguments thru.
As python-crontab is not an option I have to work with os
, sys
, subprocess
and shlex
.
I have tried to following:
commandstring = '(crontab -l 2>/dev/null; echo "0 5 5 5 * '/bin/date +%Y` == 2017 && /bin/touch filename") | crontab -'
subprocess.call(shlex.split(commandstring))
But gives me an error back. Maybe I don't understand how the shlex works and how to format the string. Or there might be a better way to do this.
What i want to achieve is that i want to use cron to create files with specific filenames and the touch command at a specific date/time and delete those file as a specific date/time. "at" is also not installed, so i have to use cron.
It seems like shell.py
would be the right way, but as I cannot install new modules, same problem as with python-crontab.