python version 2.6.6 ; pexpect 2.3

login方法解读:

def login (args, cli_username=None, cli_password=None):

    # I have to keep a separate list of host names because Python dicts are not ordered.
# I want to keep the same order as in the args list.
host_names = []
hive_connect_info = {}
hive = {}
# build up the list of connection information (hostname, username, password, port)
for host_connect_string in args:
hcd = parse_host_connect_string (host_connect_string)
hostname = hcd['hostname']
port = hcd['port']
if port == '':
# port=22
port = None
if len(hcd['username']) > 0:
username = hcd['username']
elif cli_username is not None:
username = cli_username
else:
username = raw_input('%s username: ' % hostname)
if len(hcd['password']) > 0:
password = hcd['password']
elif cli_password is not None:
password = cli_password
else:
password = getpass.getpass('%s password: ' % hostname)
host_names.append(hostname)
hive_connect_info[hostname] = (hostname, username, password, port)
print hive_connect_info
'''
return result like this
{'192.168.100.245': ('192.168.100.245', 'root', 'pwdxxx', None), '192.168.100.246': ('192.168.100.246', 'root', 'pwdxxx', None)}
'''
# build up the list of hive connections using the connection information.
for hostname in host_names:
print 'connecting to', hostname
try:
fout = file("log_"+hostname, "w")
'fout means fileout'
hive[hostname] = pxssh.pxssh()
print "hive[hostname]:",hive[hostname]
hive[hostname].login(*hive_connect_info[hostname])
'the exception happened on the last line'
print hive[hostname].before
hive[hostname].logfile = fout
print '- OK'
except Exception, e:
print '- ERROR',
print str(e)
print 'Skipping', hostname
hive[hostname] = None
return host_names, hive

上面代码 hive[hostname].login(*hive_connect_info[hostname]) 这行会出一个bug,不过还是很好修的,参考 http://stackoverflow.com/questions/21055943/pxssh-connecting-to-an-ssh-proxy-timeout-exceeded-in-read-nonblocking 可以找到解决办法:

修改 /usr/lib/python2.6/site-packages/pxssh.py 在第134行插入下面:

self.sendline() #Line 134
time.sleep(0.5) #Line 135

其下面几行正好是

self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt

Pexpect--example--hive.py解读的更多相关文章

  1. python hive.py

    #!/usr/bin/env python# -- coding:utf-8 -- import osimport sysfrom subprocess import call from pyspar ...

  2. tensorflow serving 之minist_saved_model.py解读

    最近在学习tensorflow serving,但是就这样平淡看代码可能觉得不能真正思考,就想着写个文章看看,自己写给自己的,就像自己对着镜子演讲一样,写个文章也像自己给自己讲课,这样思考的比较深,学 ...

  3. python 读取hive数据

    话不多说,直接上代码 from pyhive import hivedef pyhive(hql): conn = hive.Connection(host='HiveServer2 host', p ...

  4. ansible源码解读

    Ansible源码获取 Ansible Github:https://github.com/ansible Ansible目录结构 $ tree -L 2 ansible-2.0.0.0 ansibl ...

  5. pyhive连接hive(失败)

    一.安装pyhive pip install sasl(需要来下载至本地安装:https://download.lfd.uci.edu/pythonlibs/q4hpdf1k/sasl-0.2.1-c ...

  6. Django开发之html交互

    html中用户输入信息,由Django的view.py处理,大致用到了以下几类格式: 1. 文本框 <input type="text" name="vid&quo ...

  7. 【原创】用python连接thrift Server 去执行sql的问题总汇

    场景:python和现有产品的结合和应用——python的前瞻性调研 环境:centos7 0.首先确保安装了python和pyhive,下面是连接代码: #!/usr/bin/env python ...

  8. 【转】安装ambari的时候遇到的ambari和hadoop问题集

    5.在安装的时候遇到的问题 5.1使用ambari-server start的时候出现ERROR: Exiting with exit code -1. 5.1.1REASON: Ambari Ser ...

  9. 三行代码辨别PS

    三行代码辨别PS 博主的好友动态和朋友圈经常出现各种图片,博主很想知道这些图片有没有经过PS,于是选择了技术流-- 代码 先放代码为敬,返回结果为TRUE表示进行过PS. isPS.py #!/usr ...

随机推荐

  1. u-boot-2010.3移植到Tiny6410问题总结

    问题1: u-boot-2010.3中nand_spl文件夹的作用:实现从Nandflash启动在编译是会建立几个链接文件,用这几个链接文件生成u-boot-spl-16k.bin nand_spl/ ...

  2. JAVA常见算法题(十七)

    package com.xiaowu.demo; //输出九九乘法表. public class Demo17 { public static void main(String[] args) { t ...

  3. [置顶] kubernetes创建资源yaml文件例子--pod

    kubernetes创建pod的yaml文件,参数说明 apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 ...

  4. How to Clear setInterval() without Knowing the ID

    ProblemDeclaring a setInterval() without keeping a reference to it (which is returned from the funct ...

  5. tomcat修改默认访问首页

    找到conf下server.xml文件修改如下位置内容 <Host name="localhost" appBase="webapps" unpackWA ...

  6. nginx资源争夺问题

    nginx资源争夺问题 多个配置之间存在资源争夺的情况,需要进行整理: 学习了:https://blog.csdn.net/veryisjava/article/details/72917894 ng ...

  7. 怎么windows10下设置始终以管理员身份运行

    怎么windows10下设置始终以管理员身份运行 学习了:https://jingyan.baidu.com/article/e2284b2b6e6df8e2e7118d7a.html 可以对快捷方式 ...

  8. elasticsearch 基础性操作

    1 基础概念 Elasticsearch是一个近实时的系统,从你写入数据到数据可以被检索到,一般会有1秒钟的延时.Elasticsearch是基于Lucene的,Lucene的读写是两个分开的句柄,往 ...

  9. C++003基础

    1.C++对C的扩展 1简单的C++程序 1.1求圆的周长和面积 数据描写叙述: 半径.周长,面积均用实型数表示 数据处理: 输入半径 r. 计算周长 = 2*π*r : 计算面积 = π* r2 . ...

  10. DB门面,查询构建器,Eloquent ORM三者的CURD

    一.DB门面 1.insert DB::insert('insert into table(`name`) value(?)', ['test']); 2.update DB::update('upd ...