|
| 1 | +import os |
1 | 2 | import sys |
| 3 | +import time |
| 4 | + |
2 | 5 | sys.path.append('/usr/local/CyberCP') |
3 | 6 | import argparse |
4 | 7 | from plogical.processUtilities import ProcessUtilities |
@@ -81,13 +84,33 @@ def remCronbyLine(externalApp, line): |
81 | 84 | @staticmethod |
82 | 85 | def addNewCron(externalApp, finalCron): |
83 | 86 | try: |
| 87 | + |
84 | 88 | if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: |
85 | 89 | cronPath = "/var/spool/cron/" + externalApp |
86 | 90 | else: |
87 | 91 | cronPath = "/var/spool/cron/crontabs/" + externalApp |
88 | 92 |
|
89 | | - with open(cronPath, "a") as file: |
90 | | - file.write(finalCron + "\n") |
| 93 | + from random import randint, seed |
| 94 | + try: |
| 95 | + seed(time.perf_counter()) |
| 96 | + except: |
| 97 | + pass |
| 98 | + |
| 99 | + TempFile = '/tmp/' + str(randint(1000, 9999)) |
| 100 | + |
| 101 | + if os.path.exists(cronPath): |
| 102 | + FullCrons = open(cronPath, 'r').read() |
| 103 | + finalCron = '%s%s\n' % (FullCrons, finalCron) |
| 104 | + with open(TempFile, "w") as file: |
| 105 | + file.write(finalCron) |
| 106 | + else: |
| 107 | + with open(TempFile, "w") as file: |
| 108 | + file.write(finalCron + '\n') |
| 109 | + |
| 110 | + command = 'cp %s %s' % (TempFile, cronPath) |
| 111 | + ProcessUtilities.executioner(command) |
| 112 | + |
| 113 | + os.read(TempFile) |
91 | 114 |
|
92 | 115 | print("1,None") |
93 | 116 | except BaseException as msg: |
|
0 commit comments