歡迎您光臨本站 註冊首頁

分享一個自己寫的併發執行伺服器端命令的腳本(python)

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

分享一個自己寫的併發執行伺服器端命令的腳本(python)

 

執行條件:
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~:)

[火星人 ] 分享一個自己寫的併發執行伺服器端命令的腳本(python)已經有383次圍觀

http://coctec.com/docs/service/show-post-1221.html