分享一个自己写的并发执行服务器端命令的脚本(python)
本帖最后由 清潼止水 于 2012-01-04 21:47 编辑执行条件:
1. 安装PYTHON和所需要的模块,包括 cmd、threading、paramiko 等。
2. 需要建立本机和服务器端的SSH信任,脚本是根据SSH信任连接到远程服务器执行命令的。
说明:
脚本主要用到了三个PYTHON模块:threading、paramiko、cmd , threading模块用于并发,paramiko用于根据信任连接到远程服务器,cmd用于模拟登陆环境。
把远程服务器的IP写在当前目录下的 ipfile 里面,可以用#注销掉 , 然后运行 python exec_cmd_threading.py
登陆:# ./exec_cmd_threading.py
-------------IP:-------------
| 127.0.0.1 |
| 192.168.35.102 |
-----------------------------
please confirm:y
which user to login:root
127.0.0.1 : login OK
192.168.35.102 : login OK
As all remote servers logined OK,you can type almost commands which can be executed in shell.
Also you can ues "!$" as well as in shell,more importantly,type "quit" if you want to exit !!!
#执行命令:#echo '627645'|passwd --stdin root
192.168.35.102 : Changing password for user root.
passwd: all authentication tokens updated successfully.
127.0.0.1 : Changing password for user root.
passwd: all authentication tokens updated successfully.
#uname -r
127.0.0.1 : 2.6.18-274.7.1.el5
192.168.35.102 : 2.6.18-274.7.1.el5退出:#quit
exit...
感谢分享 回复 2# Shell_HAT
多谢 O(∩_∩)O~:)
页:
[1]