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 ...
随机推荐
- 细说JavaScript对象(1):对象的使用和属性
JavaScript 中的一切都可以视为对象,除了两个特例:null 和 undefined. false.toString(); // 'false' [1, 2, 3].toString(); / ...
- ubuntu-kvm上面deploy qcow2格式虚拟机
ubuntu-kvm完成后,将xxx.qcow2格式的镜像拷贝到ubuntu-kvm这个虚拟机上面去. 1. 若是ubuntu server没有图形界面,可以先安装desktop,参考http://w ...
- iOS用户响应者链的那些事儿
这篇文章想跟大家分享的主旨是iOS捕获用户事件的各种情况,以及内部封装的一些特殊事件. 我们先从UIButton谈起,UIButton大家使用的太多了,他特殊的地方就在于其内置的普通Default/高 ...
- 深入理解brew link命令
来源:https://newsn.net/say/brew-link-php71.html brew是mac机上面程序猿非常常用的软件包安装方式,其中有两组命令是需要大家知晓的.分别是: 第一组:br ...
- 管理 node 版本,选择 nvm 还是 n?
来源:http://taobaofed.org/blog/2015/11/17/nvm-or-n/ 引子 我本机安装着 nvm,而 node 本来一直运行在 0.x 的老版本上.后来为了跑 ES6,我 ...
- selenium执行报错:Process refused to die after 10 seconds, and couldn't taskkill it
十二月 02, 2015 5:16:56 下午 org.openqa.selenium.os.ProcessUtils killWinProcess 警告: Process refused to di ...
- Nginx user_agent、if指令及全局变量
Nginx user_agent.if指令及全局变量 1.User_agent User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本.CP ...
- 针对ecshop错误404页面的优化
在ecshop系统当中,比如你随意将商品详细页面的地址中的ID修改为一个不存在的商品ID,ecshop会自动跳转到首页.ecshop在这方面做得非常的差,甚至导致了很多的站不被搜索引擎收录.最模板提供 ...
- Spring管理的bean初始化方法的三种方式,以及@PostConstruct不起作用的原因
1:Spring 容器中的 Bean 是有生命周期的,spring 允许 Bean 在初始化完成后以及销毁前执行特定的操作.下面是常用的三种指定特定操作的方法: 通过实现InitializingBea ...
- Android学习(二十)Notification通知栏
一.通知栏的内容 1.图标 2.标题 3.内容 4.时间 5.点击后的相应 二.如何实现通知栏 1.获取NotificationManager. 2.显示通知栏:notify(id,notificat ...