I'm writing script on Python for copy cron config. I need to copy my file to /etc/cron.d/, and if destination file isn't exist it must be created. I found solution, but it doesn't provide missing file, here it is:
from shutil import copyfile
def index():
src = "/opt/stat/stat_cron"
dst = "/etc/cron.d/stat_cron"
copyfile(src, dst)
if __name__ == "__main__":
index()
I get exception "FileNotFoundError: [Errno 2] No such file or directory: '/etc/cron.d/stat_cron'"
Please, tell me correct solution.
copy()if it does not then create it. PS. Bad indentation.