Pexpect--example--hive.py解读
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解读的更多相关文章
- python hive.py
#!/usr/bin/env python# -- coding:utf-8 -- import osimport sysfrom subprocess import call from pyspar ...
- tensorflow serving 之minist_saved_model.py解读
最近在学习tensorflow serving,但是就这样平淡看代码可能觉得不能真正思考,就想着写个文章看看,自己写给自己的,就像自己对着镜子演讲一样,写个文章也像自己给自己讲课,这样思考的比较深,学 ...
- python 读取hive数据
话不多说,直接上代码 from pyhive import hivedef pyhive(hql): conn = hive.Connection(host='HiveServer2 host', p ...
- ansible源码解读
Ansible源码获取 Ansible Github:https://github.com/ansible Ansible目录结构 $ tree -L 2 ansible-2.0.0.0 ansibl ...
- pyhive连接hive(失败)
一.安装pyhive pip install sasl(需要来下载至本地安装:https://download.lfd.uci.edu/pythonlibs/q4hpdf1k/sasl-0.2.1-c ...
- Django开发之html交互
html中用户输入信息,由Django的view.py处理,大致用到了以下几类格式: 1. 文本框 <input type="text" name="vid&quo ...
- 【原创】用python连接thrift Server 去执行sql的问题总汇
场景:python和现有产品的结合和应用——python的前瞻性调研 环境:centos7 0.首先确保安装了python和pyhive,下面是连接代码: #!/usr/bin/env python ...
- 【转】安装ambari的时候遇到的ambari和hadoop问题集
5.在安装的时候遇到的问题 5.1使用ambari-server start的时候出现ERROR: Exiting with exit code -1. 5.1.1REASON: Ambari Ser ...
- 三行代码辨别PS
三行代码辨别PS 博主的好友动态和朋友圈经常出现各种图片,博主很想知道这些图片有没有经过PS,于是选择了技术流-- 代码 先放代码为敬,返回结果为TRUE表示进行过PS. isPS.py #!/usr ...
随机推荐
- @selector和SEL
遇到selector发现不是很明白,网上搜到的零零星星的介绍也不成体系,索性自己翻译一下,加深一下印象.原文来自官方API文档下的Selectors. Selectors 在OC中,selector有 ...
- 启动MongoDB时,提示:error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
启动MongoDB时,提示: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: ...
- 为docker创建ubuntu带SSH的基础镜像
安装Debootstrap ubuntu操作系统:apt install debootstrap centos操作系统:yum install debootstrap 构建基础Ubuntu的rootf ...
- 由jtable浅谈vector<vector<Object>>的用法(转自a718515028的专栏)
以前只用过vector<Object> ,但是在做从数据库导出数据放到jtable中时,发现还有个vector<vector<Object>>的用法. 先说jta ...
- thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: No worthy mechs found
thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (- ...
- Flume推送数据到SparkStreaming案例实战和内幕源码解密
本期内容: 1. Flume on HDFS案例回顾 2. Flume推送数据到Spark Streaming实战 3. 原理绘图剖析 1. Flume on HDFS案例回顾 上节课要求大家自己安装 ...
- Java高级特性—并发包
1). java并发包介绍 JDK5.0 以后的版本都引入了高级并发特性,大多数的特性在java.util.concurrent 包中,是专门用于多线程发编程的, 主要包含原子量.并发集合.同步器.可 ...
- webstorm定位如何在代码后面?
写代码的时候定位总是在任意一点,而不是在代码的最后面. 以至于写代码的时候总会莫名其妙出现很多空格之类的奇怪报错. 取消图中选项
- UVA - 434 Matty's Blocks
题意:给你正视和側视图,求最多多少个,最少多少个 思路:贪心的思想.求最少的时候:由于能够想象着移动,尽量让两个视图的重叠.所以我们统计每一个视图不同高度的个数.然后计算.至于的话.就是每次拿正视图的 ...
- 【BIEE】02_新建资料库并创建简单分析
一.新建资料库 1.开始→打开BI管理→点击新建资料库 2.文件→新建资料档案库 下一步 在下面的框中一次填入 连接类型:OCI 10g/11g(直接选择即可) 数据库名称:(DESCRIPTION ...