modify connect_one view

pull/2/head
ibuler 2014-10-30 22:11:45 +08:00
parent 93bd02017c
commit 596573293f
1 changed files with 6 additions and 7 deletions

View File

@ -109,7 +109,7 @@ def connect(host, port, user, password):
os.mkdir(log_dir) os.mkdir(log_dir)
logfile = open("%s/%s_%s_%s" % (log_dir, host, time.strftime('%Y%m%d'), user), 'a') logfile = open("%s/%s_%s_%s" % (log_dir, host, time.strftime('%Y%m%d'), user), 'a')
logfile.write('\n\n%s\n\n' % time.strftime('%Y%m%d_%H%M%S')) logfile.write('\n\n%s\n\n' % time.strftime('%Y%m%d_%H%M%S'))
cmd = 'ssh -p %s %s@%s' % (port, user, host) cmd = 'ssh -q -p %s %s@%s' % (port, user, host)
global foo global foo
foo = pexpect.spawn('/bin/bash', ['-c', cmd]) foo = pexpect.spawn('/bin/bash', ['-c', cmd])
foo.logfile = logfile foo.logfile = logfile
@ -267,15 +267,14 @@ def connect_one(username, option):
if ip_len == 1: if ip_len == 1:
ip = ip_matched[0] ip = ip_matched[0]
else: else:
for one_ip in ip_matched: if ip_input in ip_matched:
if one_ip.endswith(ip_input): ip = ip_input
ip = one_ip else:
break for one_ip in ip_matched:
else:
print one_ip print one_ip
if ip: if ip:
password = jm.decrypt(sth_select(username=username)) password = jm.decrypt(sth_select(username=username))
port = sth_select(ip=ip_input) port = sth_select(ip=ip)
print "Connecting %s ..." % ip print "Connecting %s ..." % ip
connect(ip, port, username, password) connect(ip, port, username, password)
else: else: