modify PS1

pull/6/head
root 2014-12-22 15:56:19 +08:00
parent e0a0c1c641
commit f06422d5fa
1 changed files with 6 additions and 5 deletions

View File

@ -106,7 +106,7 @@ def connect(username, password, host, port):
Connect server.
"""
ps1 = '[\u@%s \W]\$' % host
ps1 = "'[\u@%s \W]\$ '\n" % host
# Make a ssh connection
ssh = paramiko.SSHClient()
@ -114,9 +114,11 @@ def connect(username, password, host, port):
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=port, username=username, password=password, compress=True)
# Make a channel
# Make a channel and set windows size
global channel
channel = ssh.invoke_shell()
win_size = get_win_size()
channel.resize_pty(height=win_size[0], width=win_size[1])
try:
signal.signal(signal.SIGWINCH, set_win_size)
except:
@ -124,16 +126,15 @@ def connect(username, password, host, port):
# Modify PS1
channel.send('PS1=%s' % ps1)
channel.send("clear;echo -e '\\033[32mLogin %s OK.\\033[0m'\n" % host)
# Make ssh interactive tunnel
posix_shell(channel, username, host)
# shutdown channel socket
channel.shutdown()
ssh.close()
if __name__ == '__main__':
connect('guanghongwei', 'Lov@j1ax1n', '172.16.1.122', 2001)