From 506ce6a8095d0b6438252c8e2df9b3fb13b9b576 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Thu, 31 Oct 2013 18:22:37 +0100 Subject: [PATCH 1/2] remove unused function --- library/system/cron | 6 ------ 1 file changed, 6 deletions(-) diff --git a/library/system/cron b/library/system/cron index 81e411168b..c6f89682c7 100644 --- a/library/system/cron +++ b/library/system/cron @@ -341,12 +341,6 @@ class CronTab(object): result += '\n' return result - def _read_file_execute(self): - """ - Returns the command line for reading a crontab - """ - return "%s -l %s" % (CRONCMD, self._user_execute()) - def _read_user_execute(self): """ Returns the command line for reading a crontab From 9e7b02aaeeddabd6b69642ec134bcce67e2dbf35 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Thu, 31 Oct 2013 18:23:04 +0100 Subject: [PATCH 2/2] make cron module work on solaris Cron on solaris do not take the same set of option than vixie cron on linux, and among the biggest difference, root cannot set the crontab of a user directly from a file. Thus the use of su to run the crontab command. Fix issue #4648 --- library/system/cron | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/library/system/cron b/library/system/cron index c6f89682c7..3bf43b7d56 100644 --- a/library/system/cron +++ b/library/system/cron @@ -144,6 +144,7 @@ EXAMPLES = ''' import os import re import tempfile +import platform CRONCMD = "/usr/bin/crontab" @@ -345,21 +346,27 @@ class CronTab(object): """ Returns the command line for reading a crontab """ - return "%s -l %s" % (CRONCMD, self._user_execute()) + user = '' + if self.user: + if platform.system() == 'SunOS': + return "su '%s' -c '%s -l'" % (self.user, CRONCMD) + else: + user = '-u %s' % self.user + return "%s %s %s" % (CRONCMD , user, '-l') def _write_execute(self, path): """ Return the command line for writing a crontab """ - return "%s %s %s" % (CRONCMD, self._user_execute(), path) - - def _user_execute(self): - """ - User command switches to append to the read and write commands. - """ + user = '' if self.user: - return "%s %s" % ('-u', str(self.user)) - return '' + if platform.system() == 'SunOS': + return "chown %s %s ; su '%s' -c '%s %s'" % (self.user, path, self.user, CRONCMD, path) + else: + user = '-u %s' % self.user + return "%s %s %s" % (CRONCMD , user, path) + + #==================================================