Skip to content

Commit eb41898

Browse files
committed
bug fix: cron jobs
1 parent 238208d commit eb41898

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

plogical/cronUtil.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import os
12
import sys
3+
import time
4+
25
sys.path.append('/usr/local/CyberCP')
36
import argparse
47
from plogical.processUtilities import ProcessUtilities
@@ -81,13 +84,33 @@ def remCronbyLine(externalApp, line):
8184
@staticmethod
8285
def addNewCron(externalApp, finalCron):
8386
try:
87+
8488
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
8589
cronPath = "/var/spool/cron/" + externalApp
8690
else:
8791
cronPath = "/var/spool/cron/crontabs/" + externalApp
8892

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)
91114

92115
print("1,None")
93116
except BaseException as msg:

0 commit comments

Comments
 (0)