def main(): if DEBUG: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-18s %(levelname)-8s ' '%(message)s', datefmt='%m-%d %H:%M', filename='rbssh.log', filemode='w') logging.debug('%s' % sys.argv) logging.debug('PID %s' % os.getpid()) ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(logging.Formatter('%(message)s')) ch.addFilter(logging.Filter('root')) logging.getLogger('').addHandler(ch) path, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, options.username) if username is None: username = getpass.getuser() logging.debug('!!! %s, %s, %s' % (hostname, username, command)) client = sshutils.get_ssh_client(options.local_site_name) client.set_missing_host_key_policy(paramiko.WarningPolicy()) attempts = 0 password = None key = sshutils.get_user_key(options.local_site_name) while True: try: client.connect(hostname, username=username, password=password, pkey=key, allow_agent=options.allow_agent) break except paramiko.AuthenticationException, e: if attempts == 3 or not sys.stdin.isatty(): logging.error('Too many authentication failures for %s' % username) sys.exit(1) attempts += 1 password = getpass.getpass("%s@%s's password: " % (username, hostname)) except paramiko.SSHException, e: logging.error('Error connecting to server: %s' % e) sys.exit(1)
def main(): if DEBUG: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-18s %(levelname)-8s ' '%(message)s', datefmt='%m-%d %H:%M', filename='rbssh.log', filemode='w') logging.debug('%s' % sys.argv) logging.debug('PID %s' % os.getpid()) ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(logging.Formatter('%(message)s')) ch.addFilter(logging.Filter('root')) logging.getLogger('').addHandler(ch) path, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, options.username) if username is None: username = getpass.getuser() logging.debug('!!! %s, %s, %s' % (hostname, username, command)) client = sshutils.get_ssh_client() client.set_missing_host_key_policy(paramiko.WarningPolicy()) attempts = 0 password = None success = False while True: try: client.connect(hostname, username=username, password=password) break except paramiko.AuthenticationException, e: if attempts == 3 or not sys.stdin.isatty(): logging.error('Too many authentication failures for %s' % username) sys.exit(1) attempts += 1 password = getpass.getpass("%s@%s's password: " % (username, hostname)) except paramiko.SSHException, e: logging.error('Error connecting to server: %s' % e) sys.exit(1)
def main(): if DEBUG: global debug_fp fd, name = tempfile.mkstemp(prefix='rbssh', suffix='.log') debug_fp = os.fdopen(fd, "w+b") fp.write('%s\n' % sys.argv) fp.write('PID %s\n' % os.getpid()) path, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, None) debug('%s, %s, %s\n' % (hostname, username, command)) client = sshutils.get_ssh_client() client.connect(hostname, username=username) transport = client.get_transport() channel = transport.open_session() channel.exec_command(' '.join(command)) if os.name == 'posix': begin_posix(channel) else: begin_windows(channel) status = channel.recv_exit_status() client.close() if debug_fp: fp.close() return status