def run(self, user, password, *options): """ Run a shell command. The command is executed as: "su - <user> -c <cmd>" and the user/password is authenticated using PAM. :param user: A user name. :type user: str :param password: The password. :type password: str :param options: List of options. :type options: list :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ if not authenticate(user, password): return os.EX_NOPERM, {} shell = _Shell() context = Context.current() path = os.path.join("/tmp", context.sn) fp = open(path, "w+") try: fp.write(self.content) finally: fp.close() try: os.chmod(path, 0755) cmd = [path] cmd += options cmd = " ".join(cmd) return shell.run("su", "-", user, "-c", cmd) finally: os.unlink(path)
def run(self, user, password, *options): """ Run a shell command. The command is executed as: "su - <user> -c <cmd>". :param user: A user name. :type user: str :param password: The password. :type password: str :param options: List of options. :type options: list :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ shell = _Shell() context = Context.current() path = os.path.join('/tmp', context.sn) with open(path, 'w+') as fp: fp.write(self.content) try: os.chmod(path, 0o755) cmd = [path] cmd += options cmd = ' '.join(cmd) return shell.run('su', '-', user, '-c', cmd) finally: os.unlink(path)
def run(self, user, password, *options): """ Run a shell command. The command is executed as: "su - <user> -c <cmd>" and the user/password is authenticated using PAM. :param user: A user name. :type user: str :param password: The password. :type password: str :param options: List of options. :type options: list :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ if not authenticate(user, password): return os.EX_NOPERM, {} shell = _Shell() context = Context.current() path = os.path.join('/tmp', context.sn) fp = open(path, 'w+') try: fp.write(self.content) finally: fp.close() try: os.chmod(path, 0755) cmd = [path] cmd += options cmd = ' '.join(cmd) return shell.run('su', '-', user, '-c', cmd) finally: os.unlink(path)
def start(self): """ Start the named service. :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ shell = _Shell() return shell.run("service", self.name, "start")
def stop(self): """ Stop the named service. :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ shell = _Shell() return shell.run('service', self.name, 'stop')
def restart(self): """ Restart the named service. :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ shell = _Shell() return shell.run('service', self.name, 'restart')
def cancel(self): """ Cancel a scheduled shutdown; halt() or reboot(). :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple :see: shutdown(8) """ shell = _Shell() return shell.run("shutdown", "-c")
def cancel(self): """ Cancel a scheduled shutdown; halt() or reboot(). :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple :see: shutdown(8) """ shell = _Shell() return shell.run('shutdown', '-c')
def run(self, cmd): """ Run a shell command. The command is executed as: "su - <user> -c <cmd>". :param cmd: The command & arguments. :type cmd: str :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ shell = _Shell() return shell.run('su', '-', self.user, '-c', cmd)
def reboot(self, when=1): """ Reboot the system. :param when: When to perform the reboot. One of: - now : immediate. note: reply not sent. - +m : where m is minutes. - hh:mm : time (hours:minutes) 24hr clock. :type when: str :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple :see: shutdown(8) """ shell = _Shell() return shell.run("shutdown", "-r", when, "&")
def reboot(self, when=1): """ Reboot the system. :param when: When to perform the reboot. One of: - now : immediate. note: reply not sent. - +m : where m is minutes. - hh:mm : time (hours:minutes) 24hr clock. :type when: str :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple :see: shutdown(8) """ shell = _Shell() return shell.run('shutdown', '-r', when, '&')
def run(self, cmd): """ Run a shell command. The command is executed as: "su - <user> -c <cmd>" and the user/password is authenticated using PAM. :param cmd: The command & arguments. :type cmd: str :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ if authenticate(self.user, self.password): shell = _Shell() return shell.run("su", "-", self.user, "-c", cmd) else: return os.EX_NOPERM, {}
def run(self, cmd): """ Run a shell command. The command is executed as: "su - <user> -c <cmd>" and the user/password is authenticated using PAM. :param cmd: The command & arguments. :type cmd: str :return: (status, {stdout:<str>, stderr:<str>}) :rtype: tuple """ if authenticate(self.user, self.password): shell = _Shell() return shell.run('su', '-', self.user, '-c', cmd) else: return os.EX_NOPERM, {}