polysh主页:
安装
安装前提python版本>2.4 安装方法:pip install polysh
使用
说明
在使用polysh连接远程shell后,
- 命令前面的
:
表示,所有的命令都是在与polysh交互,并且命令不会发送到远程shell - 在命令前的
!
表示在本地shell中执行,不会发送到远程shell
常用方法
- 主机名登录:
polysh 'hostname-preffix-<number01-nunmber05>'
- polysh帮助:连接远程主机后,输入
:help
ready (15)> :help:add 添加远程连接Add one or many remote shells.:chdir 改变本地工作目录(不是远程目录)Change the current directory of polysh (not the remote shells).:disable 关闭发送命令到远程shell功能Disable sending commands to remote shells.:enable 启用发送命令到远程shell功能Enable sending commands to remote shells.:export_vars 在远程shell定义环境变量Export some environment variables on enabled remote shells.:help 帮助列表List control commands or show their documentations.:hide_password Do not echo the next typed line.:list 列出远程shell和对应的状态List remote shells and their states.:purge 删除失效远程shell Delete disabled remote shells.:quit 登出polysh Quit polysh.:reconnect 重新连接已断开连接的远程shell Try to reconnect to disconnected remote shells.:rename 重命名Rename all enabled remote shells with the argument.:replicate 复制文件Copy a path from one remote shell to all others:reset_prompt Change the prompt to be recognized by polysh.:send_ctrl Send a control character to remote shells.:set_debug Enable or disable debugging output for remote shells.:set_log 将命令窗口输出到指定本地文件Duplicate every console I/O into the given local file.:show_read_buffer Print the data read by remote shells.:upload Upload the specified local path to enabled remote shells.
- 推出polysh:连接远程主机后
:quit
polysh交互命令详解
说明:一下所有都是在已进入polysh
一下所有交互注意命令前面的符号:
:
表示与polysh交互;!
表示与本地shell交互
add
例子::add hostname
将hostname shell添加到polysh批量处理的shell集合
chdir
例子::chdir testdir
将本地工作目录变更到原工作目录下的子文件夹testdir。
可以在测试前后使用
!pwd
查看本地工作目录,并对比。 我的在使用:chdir
前!pwd
输出/opt/home/heguangfu/
,:chdir test
后输出/opt/home/heguangfu/test
disable和enable
例子1::disable
使所有的连接不处于激活状态,发送命令不会发送到远程shell。polysh交互提示由ready (15)>
变为ready (0)>
。
此处使用
:enable
重新启用所有远程连接。
例子2::disable hostname
使指定远程shell失效。
此处使用
:enable hostname
重新启用指定远程shell的连接。
例子3::enable worker16
只启用worker16远程shell,其余的不启用。可实现对该shell单独操作。
此处使用
:enable
重新启用所有远程连接。
list
例子::list
列出所有连接和状态。
ready (14)> :listworker16 disabled idle: colors=/home/heguangfu/.dircolorsworker17 enabled idle: colors=/home/heguangfu/.dircolorsworker18 enabled idle: colors=/home/heguangfu/.dircolorsworker19 enabled idle: colors=/home/heguangfu/.dircolorsworker20 enabled idle: colors=/home/heguangfu/.dircolors
之前使用:disable
的远程shell状态为disable状态(worker16),其余为enable状态。
purge
例子:purge
,删除出狱disable状态的远程shell。
worker17 enabled idle: colors=/home/heguangfu/.dircolorsworker18 enabled idle: colors=/home/heguangfu/.dircolorsworker19 enabled idle: colors=/home/heguangfu/.dircolorsworker20 enabled idle: colors=/home/heguangfu/.dircolors
没有worker16的连接和状态信息了。
如果在disable后,执行purge,那么就不能使用enable回复之前的连接了。
rename
例子1::rename XXX
将所有:list
可以查看到的远程shell改名为XXX(原来是个主机hostname)。 改名后第一个为XXX,第二个为XXX#1,第10个为XXX#10。。。以此类推
例子2::rename AAA XXX
, 将所有shell改名为AAA XXX
+编号。
使用这种方式改名不知道怎么使用改变后的shell名来执行操作。。。求有知道的大神指教!
改名后,所有polysh交互命令均需要使用改名后的名字操作,例如想将原名字为worker16,现名为XXX的shell disable,必须使用现有名去操作。
replicate
例子::replicate worker16:filename
。将worker16上的文件filename发送到所有其它enable的远程shell。
:replicate
只能将文件从一个远程shell发送到其余远程shell。
set_log
将命令窗口输出到指定本地文件 例子::set_log /tmp/log
,将远程shell输出到本地指定文件中。
set_debug
开启和关闭远程shell的调试。
例子::set_debug y
,开启调试。 调试输出:
dx:aaa#11 : /home/xxx[dbg] dx:aaa#11[running]: state => idle[dbg] dx:aaa#12[running]: ==> /home/xxx\npolysh-4wBrH:prompt:YcWrA:13/\n
例子::set_debug n
, 关闭调试。