IT기술 관련/파이썬_루비 등 언어
[파이썬] 특정 파일 서버 가동후 가져오기
호레
2016. 9. 20. 14:48
반응형
__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 !! --------"
반응형