Skip to content
Snippets Groups Projects
Commit 2d09626a authored by David Verelst's avatar David Verelst
Browse files

launch.py: only add cronjob to crontab if it does not exist

parent fcba21b9
No related branches found
No related tags found
No related merge requests found
......@@ -113,10 +113,26 @@ def write_crontab(every_min=5):
f.write(crontab)
f.flush()
f.close()
cmd = 'crontab %s' % fpath
# does the current crontab already exist?
cmd = 'crontab -l'
p = sproc.Popen(cmd, stdout=sproc.PIPE, stderr=sproc.STDOUT, shell=True)
stdout = p.stdout.readlines()
p.wait()
crontab_exists = False
for line in stdout:
if line.find(cwd) > -1 and line.find(launch) > -1:
# current crontab job is already running!
crontab_exists = True
break
if not crontab_exists:
cmd = 'crontab %s' % fpath
p = sproc.Popen(cmd, stdout=sproc.PIPE, stderr=sproc.STDOUT, shell=True)
stdout = p.stdout.readlines()
p.wait()
print "added launch.py to crontab:"
print crontab
def remove_crontab():
cmd = 'crontab -r'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment