def submit(crontab, username=None, password=None): """Submit a crontab via the crontab program. Supply a crontab object. If it is to be installed for a different user supply the `username` parameter. If this is not run as root, then sudo is used and you must supply your own password for sudo.""" if username is None: ct = proctools.spawnpipe("crontab -") ct.write(str(crontab)) ct.close() return ct.wait() else: if os.getuid() == 0: ct = proctools.spawnpipe("crontab -u %s -" % (username, )) ct.write(str(crontab)) ct.close() return ct.wait() else: from pycopia import sudo if password is None: from pycopia import tty password = tty.getpass("Your password:"******"crontab -u %s -" % (username, ), password=password) ct.write(str(crontab)) ct.close() return ct.wait()
def XXXtest_sudo(self): pw = sudo.getpw() proc = sudo.sudo("/bin/ifconfig -a", password=pw) print(proc.read()) print(repr(proc.readerr())) proc.wait() sudo.sudo_reset()
def submit(crontab, username=None, password=None): """Submit a crontab via the crontab program. Supply a crontab object. If it is to be installed for a different user supply the `username` parameter. If this is not run as root, then sudo is used and you must supply your own password for sudo.""" if username is None: ct = proctools.spawnpipe("crontab -") ct.write(str(crontab)) ct.close() return ct.wait() else: if os.getuid() == 0: ct = proctools.spawnpipe("crontab -u %s -" % (username,)) ct.write(str(crontab)) ct.close() return ct.wait() else: from pycopia import sudo if password is None: from pycopia import tty password = tty.getpass("Your password:"******"crontab -u %s -" % (username,), password=password) ct.write(str(crontab)) ct.close() return ct.wait()