mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
506ce6a809
commit
9e7b02aaee
1 changed files with 16 additions and 9 deletions
|
@ -144,6 +144,7 @@ EXAMPLES = '''
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import platform
|
||||||
|
|
||||||
CRONCMD = "/usr/bin/crontab"
|
CRONCMD = "/usr/bin/crontab"
|
||||||
|
|
||||||
|
@ -345,21 +346,27 @@ class CronTab(object):
|
||||||
"""
|
"""
|
||||||
Returns the command line for reading a crontab
|
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):
|
def _write_execute(self, path):
|
||||||
"""
|
"""
|
||||||
Return the command line for writing a crontab
|
Return the command line for writing a crontab
|
||||||
"""
|
"""
|
||||||
return "%s %s %s" % (CRONCMD, self._user_execute(), path)
|
user = ''
|
||||||
|
|
||||||
def _user_execute(self):
|
|
||||||
"""
|
|
||||||
User command switches to append to the read and write commands.
|
|
||||||
"""
|
|
||||||
if self.user:
|
if self.user:
|
||||||
return "%s %s" % ('-u', str(self.user))
|
if platform.system() == 'SunOS':
|
||||||
return ''
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#==================================================
|
#==================================================
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue