반응형
__author__ = 'Administrator'
import xlrd
from paramiko import SSHClient
from scp import SCPClient
import paramiko
def scp_go(ipaddr,usename,pww,spath,opath):
ssh = SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ipaddr,username=usename,password=pww)
ssh.exec_command('mkdir sg_test')
# SCPCLient takes a paramiko transport as its only argument
scp = SCPClient(ssh.get_transport())
scp.put(spath,'sg_test')
ssh.exec_command('chmod 755 sg_test/linux.sh')
stdin,stdout,stderr = ssh.exec_command('cd ./sg_test; ./linux.sh')
print stdout.readlines()
ssh.exec_command('cd ./sg_test; mv *.txt '+ipaddress+'.txt')
scp.get('sg_test/'+ipaddress+'.txt',opath)
ssh.exec_command('rm -rf ./sg_test')
scp.close()
print 'input excel file path'
print 'ex) d:\\000\id_info.xlsx'
xlpath = raw_input("input excel file path: ")
print 'input .sh file path'
print 'ex) d:\\000\linux.sh'
shpath = raw_input("input .sh file path: ")
print 'input output file path'
print 'ex) d:\\000'
outpath = raw_input("input output path: ")
wb = xlrd.open_workbook(xlpath)
ws = wb.sheet_by_index(0)
ncol = ws.ncols # number of col
nlow = ws.nrows # number of low
print "-------- Starting engine.. --------"
i = 0
j = 0
low = []
list = []
while i < nlow :
while j < ncol :
if j == 0 :
ipaddress = str(ws.row_values(i)[j])
elif j == 1 :
name = str(ws.row_values(i)[j])
elif j == 2 :
pw = str(ws.row_values(i)[j])
j += 1
scp_go(ipaddress,name,pw,shpath,outpath)
i += 1
j = 0
print "-------- Finished !! --------"
반응형
'IT기술 관련 > 파이썬_루비 등 언어' 카테고리의 다른 글
[PYTHON 3] Tutorials 24. 웹 크롤러(like Google) 만들기 1 - How to build a web crawler (1) | 2017.02.02 |
---|---|
[파이썬] typeError: isinstance() arg 2 must be a type or tuple of types 에러 해결 (0) | 2016.09.21 |
[python]특정 파일 서버에서 실행시키고 결과 가져오기 (0) | 2016.09.20 |
파이썬 SCP 오픈 소스 (0) | 2016.09.20 |
paramiko ssh 및 scp 데모 (0) | 2016.09.12 |