資源簡(jiǎn)介
expect+python組合實(shí)現(xiàn)一鍵SSH

代碼片段和文件信息
#!/usr/bin/python
import?subprocess
import?os
file_dir=‘/home/hosts‘
with?open(file_dir)?as?data:
????for?each_line?in?data.readlines():
????????if?each_line?!=?‘‘:
????????????(ippasswd)=each_line.split(‘:‘2)
????????????print(‘./noscp.exp?~/.ssh/authorized_keys?‘+ip+‘:~/.ssh?‘+‘root?‘+passwd.strip(‘\n‘))
????????????subprocess.Popen(‘./noscp.exp?~/.ssh/authorized_keys?‘+ip+‘:~/.ssh?‘+‘root?‘+passwd.strip(‘\n‘)shell=True)
??????????#??subprocess.Popen(‘./sshkey.exp?‘+ip+‘?root?‘+passwd+‘?\\|?grep?ssh-rsa?>>?~/.ssh/authorized_keys‘shell=True)
????????else:
????????????pass
#subprocess.Popen(‘chmod?755?~/.ssh/authorized_keys‘shell=True)
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-01-10?19:01??批量打通ssh腳本\
?????文件??????????81??2015-01-10?18:54??批量打通ssh腳本\hosts
?????文件?????????416??2015-01-10?18:53??批量打通ssh腳本\noscp.exp
?????文件?????????280??2015-01-10?19:01??批量打通ssh腳本\readme.txt
?????文件?????????930??2015-01-10?18:52??批量打通ssh腳本\sshkey.exp
?????文件?????????652??2015-01-10?18:54??批量打通ssh腳本\ssh_distribute.py
?????文件?????????732??2015-01-10?18:53??批量打通ssh腳本\ssh_setup.py
評(píng)論
共有 條評(píng)論