Python Remote execute command, publish file

Source: Internet
Author: User

Recently there is a demand, want to get some of the server running those application services, a set to see, too much effort, refer to the Ox people wrote this script, late plus a front-end page to do some simple maintenance work, do the first use, to be perfected, note: This script is lazy to install the fabric, the installation process reference: http://5973819.blog.51cto.com/5963819/1532334
1 #!/usr/bin/env python2 #Coding:utf83 ##################################################### 4 #author:wangganyu188 [email protected]5 #Last modified:2014-09-056 #Filename:sys_ops.py7 ##################################################### 8 9 Ten  One  fromFabric.apiImportEnv,run,put,get A  fromOsImportPath -  fromReImportFindAll -  fromSysImportargv the  fromFabric.context_managersImportHide -  fromTimeImportSleep -  -  +  -User='Root' +host,ip_list=[],[] Aport=' A' atTimeout = 1 -CMD,GETSRC,GETDST,PUTSRC,PUTDST ="',"',"',"',"' -  -  forIinchRange (1,len (argv) +1): -     #Print I -     ifARGV[I-1] = ='- H' orLen (argv) = = 1: in         Print """ - USAGE: to -C [cmd] the command you want the host (s) to run + - f [File] The file content multiple IP address want to connect - -P [put] The local file that is want to upload to the remote host (s) the - G [get] The remote file that is want to download to the local host * - h [help] Print $         """Panax Notoginseng      -      the     ifargv[i-1]=='- F': +         ifPath.isfile ('%s'% (argv[i]) = =True: Afile_list = open ('%s'% (Argv[i]),'R'). ReadLines () the              forLineinchfile_list: +                 #Print Line -HostIP =line.split () [0] $HOSTPW = Line.split () [1] $                 #print HostIP, ' \ n ', Hostpw - ip_list.append (HostIP) -Env.password ='%s'%HOSTPW the                 #print ip_list, ' \ n ', Env.password -     ifARGV[I-1] = ='- C':WuyiCMD =Argv[i] the  -     ifARGV[I-1] = ='- P': Wup = src = argv[i].split (',') -PUTSRC =P[0] AboutPUTDST = p[1] $  -  -     ifARGV[I-1] = ='- G': -G = src = Argv[i].split (',') AGETSRC =G[0] +GETDST = g[1]  the  - Else: $Ip_port = [] the     ifLen (ip_list)! =0: the          forIpinchip_list: theIp_port.append (IP +':'+PORT) the  -  in  the ifCMD! ="': the     defcommand (): AboutWith Hide ('Running'): theRun"%s"%CMD) the  the      forIpportinchIp_port: +Env.host_string =Ipport -         Print "Execute Command: \033[1;33;40m%s\033[0m at Host: \033[1;33;40m%s \033[0m"% (Cmd,ipport.split (':') [0]) the         Print "***************************************************************"Bayi command () the         Print '***************************************************************' the  - ifPutsrc andPutdst! ="': -     defputupload (): theWith Hide ('Running'): thePut"%s"% (PUTSRC),"%s"%(PUTDST)) the      forIpportinchIp_port: theEnv.host_string =Ipport -         Print "PUT Local file:\033[1;33;40m%s \033[0m to remote host:\033[1;33;40m%s\033[0m: \033[1;33;40m%s\033[0m"% (Putsrc,ipport.split (':') [0],PUTDST] the         Print "*****************************************************************" the putupload () the         Print "*****************************************************************"94              the  the ifGetsrc andGetdst! ="': the     defGetdown ():98With Hide ('Running'): AboutGet"%s"% (GETSRC),"%s"%(GETDST)) -      forIpportinchIp_port:101Env.host_string =Ipport102         Print "GET remote file:\033[1;33;40m%s \033[0m from host: \033[1;33;40m%s\033[0m to local \033[1;33;40m%s\033[0m"% (Getsrc,ipport.split (':') [0],GETDST]103         Print "*****************************************************************"104 Getdown () the         Print "*****************************************************************"

Python Remote execute command, publish file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.