1 defGet_sql_log (host,port,user,password,key_words,out_put_filename):2Commond='CD crm-app/;. /tailall.sh | grep%s'%Key_words3s =Paramiko. Sshclient ()4 S.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())5 S.connect (Host,port,user,password)6transport=S.get_transport ()7Channel =transport.open_session ()8 Channel.get_pty ()9 Channel.exec_command (Commond)Ten Print 'Command%s'%Commond One #print '%s '% (str (host)) AF=open (Out_put_filename,'A +') - - #F.write (str (s) ) the while1: - ifChannel.exit_status_ready (): - Break - Try: +Rl,wl,xl=select.select ([channel],[],[],1) - #Print RL + ifLen (RL) >0: ARECV=CHANNEL.RECV (65536) at Printrecv - #Print recv - #F.seek (2) - f.write (str (recv)) - F.flush () - in exceptKeyboardinterrupt: - Print("caught Control-c") to channel.close () + Try: - #open new socket and kill the Proc. the S.get_transport (). Open_session (). Exec_command ( * "pkill-9 Tail" $ )Panax Notoginseng except: - Pass the s.close () + f.close () AExit (0)
The information that has been returned is not complete until the channel.get_pty () was added.
The official documentation describes this:
get_pty
(*args, **kwds)
Request a pseudo-terminal from the server. This is usually used-creating a client channel, to ask the server to provide some basic terminal semantics for A shell invoked with invoke_shell
. It isn ' t necessary (or desirable) to the call of this method if you ' re going to exectue a single command with exec_command
.
Paramiko after you log on to the Linux host, the tail returns incomplete resolution.