免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
python寫的批量操作遠(yuǎn)程主機(jī)腳本(命令執(zhí)行,上傳、下載文件)

 
  最近在學(xué)習(xí)python,借助fabric模塊寫了個(gè)批量操作服務(wù)器的腳本  準(zhǔn)備工作:
  安裝python 2.6.5:
  tar xf Python-2.6.5.tar.bz2
  cd Python-2.6.5
  將目錄下Modules/Setup.dist文件中"readline readline.c -lreadline -ltermcap"行前的注釋去掉
  編譯安裝:
  ./configure --enable-shared
  make -j8 && make install
  安裝setuptools
  tar xf setuptools-0.6c11.tar.gz
  cd setuptools-0.6c11
  python setup.py install
  安裝fabric
  執(zhí)行安裝時(shí),軟件會(huì)自動(dòng)從網(wǎng)上查找依賴的安裝包并進(jìn)行安裝
  tar xf fabric-0.9rc2.tar.gz
  cd goosemo-fabric-1eacbf2
  python setup.py install
  ############################################################################
  pyssh腳本: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  #####################################################
  # Author: mayulin – mayulin@cy2009.com
  # Last modified: 2011-04-28 12:27
  # Filename: pssh.py
  #####################################################
  from fabric.api import env,run,put,get
  from os import path
  from re import findall
  from sys import argv
  from fabric.context_managers import hide
  from time import sleep
  USER='root'
  HOST,IP_LIST=[],[]
  PORT='22'
  PRI_KEY,PASSWORD,CMD,uSRC,uDST,dSRC,dDST='','','','','','',''
  timeout=1
  for i in range(1,len(argv)+1):
  if argv[i-1] == '-h' or len(argv)==1:
  print """
  USAGE:
  -u [user]       Use this argument to specify the user,default is 'root'
  -H [host]       The host that you want to connect
  -f [file]       The file content multiple ip address you want to connect
  -P [port]       The ssh port,default is 22
  -p [pwd|file]   You can specify password or a priviate key file to connect the host
  -c [command]    The command you want the host(s) to run
  -U [src,dst]    The local file that you want to upload to the remote host(s)
  -D [src,dst]    The remote file that you want to download to the local host
  -t [timeout]    The program running timeout,default is 1(s)
  -h              Print this help screen
  """
  if argv[i-1] == '-u':
  USER=argv[i]
  env.user='%s'%(USER)
  else:
  env.user='%s'%(USER)
  if argv[i-1] == '-H':
  arg=findall('(\d+\.\d+\.\d+\.\d+|\s+\.{3,4})',argv[i])
  for j in arg:
  if type(j).__name__ !='NoneType':
  HOST.append(j)
  else:
  print 'The HostIP input error'
  if argv[i-1] == '-P':
  PORT=argv[i]
  if argv[i-1] == '-f':
  if path.isfile('%s'%(argv[i])) == True:
  IP_LIST=open('%s'%(argv[i]),'r').readlines()
  if argv[i-1] == '-p':
  if path.isfile(argv[i]) == True:
  PRI_KEY=argv[i]
  env.key_filename='%s'%(PRI_KEY)
  else:
  PASSWORD=argv[i]
  env.password='%s'%(PASSWORD)
  if argv[i-1] == '-c':
  CMD=argv[i]
  if argv[i-1]=='-t':
  timeout=argv[i]
  SLP='sleep %s'%(timeout)
  if argv[i-1] == '-U':
  x=src=argv[i].split(',')
  uSRC=x[0]
  uDST=x[1]
  if argv[i-1] == '-D':
  y=src=argv[i].split(',')
  dSRC=y[0]
  dDST=y[1]
  else:
  IP_PORT=[]
  if len(IP_LIST)!=0:
  for k in IP_LIST:
  IP_PORT.append(k.strip()+':'+PORT)
  if len(HOST)!=0:
  for k in HOST:
  IP_PORT.append(k.strip()+':'+PORT)
  if CMD != '':
  def command():
  with hide('running'):
  run("%s;%s" %(CMD,SLP))
  for ip in IP_PORT:
  env.host_string=ip
  print "Execute command : \"%s\" at Host : %s" %(CMD,ip.split(':')[0])
  print "-------------------------------------------------"
  command()
  print "-------------------------------------------------"
  if uSRC and uDST !='':
  def upload():
  with hide('running'):
  put("%s" %(uSRC),"%s" %(uDST))
  for ip in IP_PORT:
  env.host_string=ip
  print "Upload local file : \"%s\" to Host : %s \"%s\"" %(uSRC,ip.split(':')[0],uDST)
  print "-------------------------------------------------"
  upload()
  print "-------------------------------------------------"
  if dSRC and dDST !='':
  def download():
  with hide('running'):
  get("%s" %(dSRC),"%s" %(dDST))
  for ip in IP_PORT:
  env.host_string=ip
  print "Download remote file : \"%s\" from Host : %s to local \"%s\"" %(dSRC,ip.split(':')[0],dDST)
  print "-------------------------------------------------"
  download()
  print "-------------------------------------------------"
  ###############################################################################
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
說說Rails吧,啟動(dòng)開始。 - 差沙的密碼 -- SSHWSFC‘s code - Bl...
非常詳細(xì)的 Docker 學(xué)習(xí)筆記
linux7防火墻端口映射,服務(wù)器使用firewall進(jìn)行端口映射端口轉(zhuǎn)發(fā)
Python網(wǎng)絡(luò)編程Socket應(yīng)用實(shí)例
當(dāng)Shell遇上了NodeJs
【Python】技巧
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服