Paramiko after you log on to the Linux host, the tail returns incomplete resolution.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.