paramiko 登录linux主机后执行tail后返回数据不完整解决方法。

 1 def get_sql_log(host,port,user,password,key_words,out_put_filename):
 2     commond=‘cd crm-app/;./tailall.sh | grep %s‘%key_words
 3     s = paramiko.SSHClient()
 4     s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 5     s.connect(host,port,user,password)
 6     transport=s.get_transport()
 7     channel = transport.open_session()
 8     channel.get_pty()
 9     channel.exec_command(commond)
10     print ‘command %s‘%commond
11    # print ‘%s‘ % (str(host))
12     f=open(out_put_filename,‘a+‘)
13
14    # f.write(str(dir(s)))
15     while 1:
16         if channel.exit_status_ready():
17             break
18         try:
19             rl,wl,xl=select.select([channel],[],[],1)
20             #print rl
21             if len(rl)>0:
22                 recv=channel.recv(65536)
23                 print recv
24                 #print recv
25                 #f.seek(2)
26                 f.write(str(recv))
27                 f.flush()
28
29         except KeyboardInterrupt:
30             print("Caught control-C")
31             channel.close()
32             try:
33                 # open new socket and kill the proc..
34                 s.get_transport().open_session().exec_command(
35                     "pkill -9 tail"
36                 )
37             except:
38                 pass
39             s.close()
40             f.close()
41             exit(0)

之前没有加入   channel.get_pty() ,这个一直返回的信息不完整。

官方文档这样描述:
get_pty(*args**kwds)

Request a pseudo-terminal from the server. This is usually used right after 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 call this method if you’re going to exectue a single command with exec_command.

时间: 2024-08-27 05:58:39

paramiko 登录linux主机后执行tail后返回数据不完整解决方法。的相关文章

使用远程shell工具SSH登录Linux主机,输完用户名回车后就卡住,10秒后才提示输入密码

使用远程shell工具SSH登录Linux主机,输完用户名回车后就卡住,10秒后才提示输入密码. 使用wireshark抓全过程包 因为ssh是加密了的协议,所以弄不懂里面内容是正常的,但可以加以过滤. 过滤栏:SSH 找到时间间隔大概为10s的NO.是x到y 过滤栏:frame.number>x&&frame.number<y 观察得出此处是DNS查询行为 原因:Linux服务器在收到SSH访问请求时,先会查询该客户端IP对应的PTR记录.假如经过5s没有收到回复,就再次发一

在SecureCRT中无需输入密码登录Linux主机

服务器端操作系统:CentOs 5.8客户端:SecureCRT5.1.3第一步:密钥对的生成.在SecureCRT中建立一个新的连接.protocol选ssh2hostname输入要连接的主机IP.Port输入目标主机上sshd的端口号.username输入要登录的用户名.在Authentication中的Primary选publickey.选取"Properties..."按钮.出现Public Key Properties窗口.选"Create Identity Fil

Python远程登录Linux操作系统,执行命令、创建目录、上传及下载文件

主要是创建文件: #! /bin/bash # -*- coding: utf-8 -*- import paramiko import os ssh = paramiko.SSHClient() key = paramiko.AutoAddPolicy() ssh.set_missing_host_key_policy(key) pkey = paramiko.RSAKey.from_private_key_file('/root/.ssh/id_rsa') paramiko.util.log

对多台Linux主机的执行相同的命令

最近在学习Linux集群的相关知识,实验中经常会在一大批主机上安装相同软件包.或者添加相应的配置信息,花了一点时间,写了一个shell脚本,虽然很拙劣,但还是可以满足现在的需求了,如果以后有其他需求的话,在考虑修改这个脚本的-- 控制主机:VS            192.168.2.131 被控主机1:RS1        192.168.2.132 被控主机2:RS2         192.168.2.133 #!/bin/bash # #FileName:cluster_cmd ###

用ssh远程登录Linux主机

ssh [email protected]地址 输入登录密码即可进入远程主机 用ssh远程登录Linux主机

(转)Silverlight_5_Toolkit_December_2011 安装后点击Toolkit Samples没反应的解决方法

Silverlight Toolkit官方下载地址: http://silverlight.codeplex.com/ http://blog.csdn.net/hcj116/article/details/8757849 (转)Silverlight_5_Toolkit_December_2011 安装后点击Toolkit Samples没反应的解决方法

Eclipse 新建.jsp页面后,页面头部标签报错的解决方法

Eclipse 新建.jsp页面后,页面头部标签报错的解决方法 1.报错地方: 2.解决方法: .jsp页面右键==>BUild Path ==>Configure Build Path... 3.接着 4.按步骤操作后.jsp页面就不会报错了 版权声明:本文为CSDN博主「爱吃狼的羊」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明. 原文链接:https://blog.csdn.net/weixin_39890531/article/details/78

C3P0在Linux下的Failed to get local InetAddress for VMID解决方法

com.mchange.v2.c3p0.impl.C3P0ImplUtils generateVmId 信息: Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness java.net.UnknownHostException: Along.Fedora: Along.Fedora at java.net.InetAddress.ge

执行游戏时出现0xc000007b错误的解决方法

如图,这个错误使无数玩家烦恼. 出现这个错误,可能是硬件的问题,也可能是软件的问题.可是,因为硬件引起该问题的概率非常小,而且除了更换硬件之外没有更好的解决方法,因此本文将具体介绍怎样通过软件解决此问题,这也是大家最关心的. 大致介绍一下这个错误是怎样发生的.这个错误的本意是提示内存错误,可是通常情况下并非内存存在问题,而是因为软件的问题产生了这个错误.到底是什么软件的问题呢?答案是DirectX,而且多数情况下是DirectX 9.0的问题. 或许大家会问了:我玩的游戏都有DirextX 11