kitech / parallel-ssh Goto Github PK
View Code? Open in Web Editor NEWlittle modified from original parallel-ssh for suite my work needs;
Home Page: http://nullget.sourceforge.net/?q=node/494
License: Other
little modified from original parallel-ssh for suite my work needs;
Home Page: http://nullget.sourceforge.net/?q=node/494
License: Other
原版的pssh,只在使用无密码证书登陆的时候非常方便,而对只支持密码登陆的ssh主机,则会弹出输入密码的交互提示,导致自动化脚本运行不自动了. 由于服务器比较多,并且登陆方式不一样,有的用证书,有的使用密码,所以对pssh作一点hack,以方便提高工作效率. 现在对pssh稍微做了点修改,在定义hosts.txt文件的时候,可选地加入密码项,如果检测到密码则使用sshpass这个命令来处理密码的自动输入功能.这样就能全自动进行了. 原来的hosts.txt 格式: 1. host[:port] [login] 2. [user@]host[:port] hack后的文件格式: 1. host[:port] [login[:passwd]] 2. [user[:passwd]@]host[:port] 虽然这样有些安全问题,但即使使用证书也存在同样级别的安全问题,因为如果保存hosts.txt的主机不安装,那么这主机上的登陆证书一样不安全. 把hosts.txt的权限设置与证书权限一样高,安全性是一样的. 依赖外部包: sshpass 修改的源文件: psshlib/psshutil.py bin/pssh bin/pscp bin/pnuke bin/prsync bin/pslurp
当本机第一次pssh远程主机时会失败,因为第一次ssh会出现如下选择:
Are you sure you want to continue connecting (yes/no)? yes
shell下可以用expect来处理,而python下有pexpect,希望pssh能内置此功能~
it shows
UnboundLocalError: local variable 'ssh' referenced before assignment
i check the source code and the reson is you commented ssh = ['ssh'] in line 72, and when passwd == None,this variable will not be assigned. then it died when i use -O option.
# ssh = ['ssh']
if passwd == None:
ssh = ['ssh']
# sys.stderr.write('using standard ssh method\n')
else:
cmd = ['sshpass', '-p', passwd, 'ssh']
# sys.stderr.write('using sshpass method\n')
if opts.options:
for opt in opts.options:
ssh += ['-o', opt]
if port:
ssh += ['-p', port]
if opts.ssh_args:
ssh += [opts.ssh_args]
cmd = ['rsync', '-e', ' '.join(ssh)]
i modified code like below, problem resolved.
ssh = ['ssh']
if opts.options:
for opt in opts.options:
ssh += ['-o', opt]
if port:
ssh += ['-p', port]
if opts.ssh_args:
ssh += [opts.ssh_args]
if passwd == None:
cmd = ['rsync', '-e', ' '.join(ssh)]
# sys.stderr.write('using standard ssh method\n')
else:
cmd = ['sshpass', '-p', passwd, 'rsync', '-e', ' '.join(ssh)]
# sys.stderr.write('using sshpass method\n')
pssh --help
Usage: pssh [OPTIONS] -h hosts.txt command [...]
Options:
--version show program's version number and exit
--help show this help message and exit
-h HOST_FILE, --hosts=HOST_FILE
hosts file (each line "[user@]host[:port]")
-H HOST_STRING, --host=HOST_STRING
additional host entries ("[user@]host[:port]")
主机格式还是旧的,应该是:
1. host[:port] [login[:passwd]]
2. [user[:passwd]@]host[:port]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.