|
|
@ -145,6 +145,7 @@ import os
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import tempfile
|
|
|
|
import tempfile
|
|
|
|
import platform
|
|
|
|
import platform
|
|
|
|
|
|
|
|
import pipes
|
|
|
|
|
|
|
|
|
|
|
|
CRONCMD = "/usr/bin/crontab"
|
|
|
|
CRONCMD = "/usr/bin/crontab"
|
|
|
|
|
|
|
|
|
|
|
@ -190,7 +191,8 @@ class CronTab(object):
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
raise CronTabError("Unexpected error:", sys.exc_info()[0])
|
|
|
|
raise CronTabError("Unexpected error:", sys.exc_info()[0])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
(rc, out, err) = self.module.run_command(self._read_user_execute())
|
|
|
|
# using safely quoted shell for now, but this really should be two non-shell calls instead. FIXME
|
|
|
|
|
|
|
|
(rc, out, err) = self.module.run_command(self._read_user_execute(), use_unsafe_shell=True)
|
|
|
|
|
|
|
|
|
|
|
|
if rc != 0 and rc != 1: # 1 can mean that there are no jobs.
|
|
|
|
if rc != 0 and rc != 1: # 1 can mean that there are no jobs.
|
|
|
|
raise CronTabError("Unable to read crontab")
|
|
|
|
raise CronTabError("Unable to read crontab")
|
|
|
@ -235,8 +237,8 @@ class CronTab(object):
|
|
|
|
|
|
|
|
|
|
|
|
# Add the entire crontab back to the user crontab
|
|
|
|
# Add the entire crontab back to the user crontab
|
|
|
|
if not self.cron_file:
|
|
|
|
if not self.cron_file:
|
|
|
|
# os.system(self._write_execute(path))
|
|
|
|
# quoting shell args for now but really this should be two non-shell calls. FIXME
|
|
|
|
(rc, out, err) = self.module.run_command(self._write_execute(path))
|
|
|
|
(rc, out, err) = self.module.run_command(self._write_execute(path), use_unsafe_shell=True)
|
|
|
|
os.unlink(path)
|
|
|
|
os.unlink(path)
|
|
|
|
|
|
|
|
|
|
|
|
if rc != 0:
|
|
|
|
if rc != 0:
|
|
|
@ -350,9 +352,9 @@ class CronTab(object):
|
|
|
|
user = ''
|
|
|
|
user = ''
|
|
|
|
if self.user:
|
|
|
|
if self.user:
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
return "su '%s' -c '%s -l'" % (self.user, CRONCMD)
|
|
|
|
return "su %s -c '%s -l'" % (pipes.quote(self.user), pipes.quote(CRONCMD))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
user = '-u %s' % self.user
|
|
|
|
user = '-u %s' % pipes.quote(self.user)
|
|
|
|
return "%s %s %s" % (CRONCMD , user, '-l')
|
|
|
|
return "%s %s %s" % (CRONCMD , user, '-l')
|
|
|
|
|
|
|
|
|
|
|
|
def _write_execute(self, path):
|
|
|
|
def _write_execute(self, path):
|
|
|
@ -362,10 +364,10 @@ class CronTab(object):
|
|
|
|
user = ''
|
|
|
|
user = ''
|
|
|
|
if self.user:
|
|
|
|
if self.user:
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
return "chown %s %s ; su '%s' -c '%s %s'" % (self.user, path, self.user, CRONCMD, path)
|
|
|
|
return "chown %s %s ; su '%s' -c '%s %s'" % (pipes.quote(self.user), pipes.quote(path), pipes.quote(self.user), CRONCMD, pipes.quote(path))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
user = '-u %s' % self.user
|
|
|
|
user = '-u %s' % pipes.quote(self.user)
|
|
|
|
return "%s %s %s" % (CRONCMD , user, path)
|
|
|
|
return "%s %s %s" % (CRONCMD , user, pipes.quote(path))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|