linux 操做系統python
expect分發密鑰linux
sublime綠色版本shell
選擇一個目錄裏面新建一個.exp文件,裏面內容爲:windows
#!/usr/bin/expect if { $argc !=2 } { send_user "usege:expect 320.exp file host" exit } #define var set file [lindex $argv 0] set host [lindex $argv 1] set password "123456" spawn ssh-copy-id -i $file "s-linuxad@$host" expect { "yes/no" {send "yes\r";exp_continue} "*password" {send "$password\r"} } expect eof
而後新建一個shell 腳本:api
#!/bin/bash . /etc/init.d/functions for ip in `cat list` do expect 320.exp ~/.ssh/id_dsa.pub $ip if [ $? -eq 0 ];then action "$ip" /bin/true else action "$ip" /bin/false fi done
新建一個list 文件,裏面放入你要分發的密鑰便可bash
[s-linuxad@T-Ansible-v-szzb scripts]$ cat list 172.31.1.32 172.31.1.221 10.0.5.146 10.0.100.10 10.0.100.11
執行的時候能夠選擇把輸出過程輸出到一個文件裏面:./start.sh >/tmp/file.txt 能夠追溯回去服務器
利用ansible 的ping 模塊來操做 主要編輯/etc/ansible/hosts的文件,通常150臺服務器放一個模塊ssh
利用命令 ansible hosts -m ping >/tmp/file.xt測試
查看輸出文件的內容網站
10.0.100.19 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n", "unreachable": true } 10.0.5.146 | SUCCESS => { "changed": false, "ping": "pong"
文件中success則爲分發密鑰成功的,若是出現不是success 就是沒有成功的
去網站下sublime 和python windows版本
https://www.python.org/
http://www.sublimetext.com/3
注:安裝時勾選「Add to explorer context menu」,表示添加到鼠標的右鍵菜單
安裝插件管理器 Package Control
使用 [Ctrl + `] (或View > Show Console menu) 打開Sublime Text控制檯,將下面的Python代碼粘貼到控制檯後按回車。
import urllib.request,os,hashlib; h = '6f4c264a24d933ce70df5dedcf1dcaee' + 'ebe013ee18cced0ef93d5f746d80ef60'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
用Package Control安裝插件
按Ctrl+Shift+P調出命令面板
輸入Install Package 選項並回車。
輸入要安裝的插件名,回車安裝
安裝 Anaconda 插件
利用Package Control安裝Anaconda。安裝後修改Anaconda配置文件:
Preferences > Package Settings > Anaconda > Settings – User
系統屬性-環境變量
{ "pep8_ignore": [ "E501", ], "complete_parameters": true, "anaconda_linting_behaviour": "save-only",// always "anaconda_gutter_theme": "hard", "anaconda_linter_show_errors_on_save": true, "python_interpreter": "C:/Python35-32/python.exe", "anaconda_linting": false, }
其中"python_interpreter"改成本身電腦的python的路徑。保存後重啓sublime
添加腳本.py,注意本地要保存的擴展名是.py的
import re import os result_path = 'D:\\tmp\\' os.chdir('D:\\tmp\\ansible-ping') ip_files = os.listdir(os.getcwd()) print(ip_files)b for ip_file in ip_files: with open(ip_file) as f: c = f.read() ip_list = re.findall(r'([\d\.]+).*[^SUCCESS] =>', c) with open(os.path.join(result_path, ip_file), 'w') as f: ip_list = map(lambda x: x+os.linesep, ip_list) f.writelines(ip_list)
最後執行的結果: