Implement Xshell and CRT Automation login

Source: Internet
Author: User
Tags readline

Log in to the Bastion machine via Xshell or CRT and then log on to the host, each time entering the password is too cumbersome. So I wrote this automated tool.


Main code:

#!/usr/bin/env python#-*- coding: utf-8 -*-import sysdefault_encoding =  ' Utf-8 ' if sys.getdefaultencoding ()  != default_encoding:    reload (SYS)      sys.setdefaultencoding (default_encoding) import xlrdimport osimport shutil  sheet_name=[u ' TP application list ', U ' TP server list ', U ' cc application list ', U ' cc server list ', U ' FP application list ', U ' FP server list ', U ' EC application list ', U ' EC server List ', U ' pa application list ', u ' PA server list ', U ' outsourced application list ', U ' outsourced server List ']filedir=os.path.dirname (Os.path.abspath (__file__)) If len (SYS.ARGV)!=2:         raise assertionerror (' requires parameter: Config path ') #ininame =sys.argv[1]+ ". INI "Confpath=sys.argv[1].rstrip ("/sessions ") if not os.path.exists (confpath+"/vbs/"):         os.makedirs (confpath+ "/vbs/") #ininamepath =os.path.join (Filedir, "Ininame") # Ininames=os.listdir (Ininamepath) #inidir =os.path.join (filedir, "INI") vbsdir=os.path.join (Confpath, "VBS") path= Os.path.join (Filedir, "howBuy.xls ")     class datatosql:        def  __init__ (Self,path):                 self.data = xlrd.open_workbook (PATH)              def datatosql (self,num,string):         Sysdata=self.data.sheet_by_name (Sheet_name[num])         sysrows =  sysdata.nrows        if os.path.exists (confpath+ "/Sessions/ "+string):             shutil.rmtree (confpath+"/ sessions/"+string)                  for sysrow in range (1,sysrows):             sysrowvalue&Nbsp;= sysdata.row_values (Sysrow)              Ip=sysrowvalue[1].strip ()             ipvbs= Os.path.join (vbsdir,ip+ ". vbs")             appname= string+ "/" +sysrowvalue[0].strip ()             # Ipvbs1=os.path.join (vbsdir,appname+ '/' +ip+ ". vbs")               #ipvbs2 =os.path.join (vbsdir,appname)               #appnamepath =os.path.join (inidir,appname)                               if not os.path.exists (confpath+ "/sessions/" +appname):                                  os.makedirs (confpath+ "/sessions/" +appname)                          file_object_read  = open (confpath+ "/sessions/10.50.50.245.xsh",  ' R ')                   stringsave= ""                stringread=file_object_read.readline ()                while stringread:                   stringread= Stringread.replace (' scriptpath= ',  ' scriptpath= ' +confpath+ ' \\vbs\\ ' +ip+ '. vbs ')                    stringsave=stringsave+stringread                   stringread=file_object_read.readline ()               file_object_save =  open (confpath+ "/sessions/" +appname+ "/" +ip+ ". Xsh",  ' W ')                file_object_save.write (Stringsave)                file_object_read.close ()                file_object_save.close ()                 if not os.path.exists (Ipvbs):                                                   file_object_read = open (filedir+ "/" + "Xshellvbs.txt",  ' R ')                 stringsave= ""                 stringread= File_object_read.readline ()                  while stringread:                     stringread=stringread.replace (' Tihuan ', '/I: ' +ip ')                       stringsave=stringsave+stringread                  &nBsp;  stringread=file_object_read.readline ()                   file_object_save = open (ipvbs,  ' W ')                  file_object_save.write ( Stringsave)                  File_object_read.close ()                  file_object_save.close ()                          data=datatosql (PATH) try:     data.datatosql (1, "TP") except:    print  "Tp no data"           try:    data.datatosql (3, "CC") except:     print "Cc no data"   try:    data.datatosql (5, "FP") except:     print  "Fp no data"         try:     data.datatosql (7, "EC") except:    print  "Ec no data"         try:    data.datatosql (9, "PA") except:    print   "Pa no data"        try:     Data.datatosql (One, "WB") except:    print  "Wb no data"

Implementation Picture: Double-click to implement Login

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/88/31/wKiom1frUzfRM8LVAAHu_5zjtYc368.png-wh_500x0-wm_3 -wmp_4-s_562371005.png "title=" _20160928131812.png "alt=" Wkiom1fruzfrm8lvaahu_5zjtyc368.png-wh_50 "/>

This article from the "12109115" blog, reproduced please contact the author!

Implement Xshell and CRT Automation login

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.