#!/usr/bin/env python
#luohongjiang
#qq:123769752
import os,sys,pexpect,getopt
password="1"
src=""
dst=""
IP="192.168.6.240"
os.system("clear")
os.system(">~/.ssh/known_hosts")
opts,var=getopt.getopt(sys.argv[1:],"i:s:r:p:h","help")
for opt,var in opts:
if opt in ("-s"):
src=var
src=os.getcwd()+"/"+src
elif opt in ("-r"):
dst=var
elif opt in ("-h","--help"):
print "help"
sys.exit(0)
elif opt in ("-p"):
password=var
elif opt in ("-i"):
IP=var
print "srcfile=%s,dstfile=%s" % (src,dst)
print "ip=%s password=%s" % (IP,password)
#os.system("read -p 'any key continue' r")
for ip in IP.split():
scp=pexpect.spawn("scp -r %s root@%s:%s" % (src,ip,dst))
for i in range(2):
i=scp.expect(["(yes/no)","password:"])
if (i==0):
#print "yes"
scp.sendline("yes")
elif (i==1):
scp.sendline(password)
scp.read()
print "copy file sucess[%s]" % ip
阅读(702) | 评论(0) | 转发(0) |