利用SecureCRT實現網路裝置自動備份-華為、H3C篇

來源:互聯網
上載者:User

標籤:interface   文字檔   password   ip地址   enable   crt   


(1)建立文字檔(注意儲存路徑,本次測試路徑為D:\backup\list.txt):


  x.x.x.x username password enable_password   (#註:如果沒有enable密碼可以不寫;每項用空格分割)


(2)建立文字檔H3C.txt(路徑D:\backup\H3C.txt),內容如下:


# $language = "VBScript"

# $interface = "1.0"

‘本指令碼示範:從一個檔案裡面自動讀取裝置IP地址,密碼等,自動將裝置配置備份

Sub Main

     ‘開啟儲存裝置管理地址以及密碼的檔案

     Const ForReading = 1, ForWriting = 2, ForAppending = 8

     Dim fso,file1,line,str1,params

     Set fso = CreateObject("Scripting.FileSystemObject")

     Set file1 = fso.OpenTextFile("D:\backup\list.txt",Forreading, False)        

     crt.Screen.Synchronous = True

     DO While file1.AtEndOfStream <> True

        ‘讀出每行

        line = file1.ReadLine

        ‘分離每行的參數 IP地址 密碼 En密碼

        params = Split (line)

       crt.session.LogFileName = "D:\backup\h3c\201611\" & params(0) & ".txt"

       crt.session.Log(true)

        ‘Telnet到這個裝置上

        crt.Session.Connect "/TELNET " & params(0)


        crt.Screen.WaitForString "Username:" 

        crt.Screen.Send params(1) & Chr(13)

        

        ‘輸入telnet密碼

        crt.Screen.WaitForString "Password:"

        crt.Screen.Send params(2) & Chr(13)

        ‘進特權模式

        crt.Screen.Send "sup" & Chr(13)

        crt.Screen.WaitForString "Password:"

        crt.Screen.Send params(3) & Chr(13)

        crt.Screen.waitForString ">"

         ‘備份目前runing-config配置

        str1 = "disp cur "

        crt.Screen.Send str1 & Chr(13)

        crt.Screen.WaitForString " ---- More ----"

        crt.Screen.Send "                "

        ‘crt.Screen.Send Chr(13)                                                                                                                                                      " & vbcr

        ‘備份完成後退出

        crt.Screen.waitForString  "return"

        crt.Screen.waitForString ">" 

        ‘執行disp int br命令 

        crt.Screen.Send "disp int brief" & Chr(13)

        crt.Screen.WaitForString " ---- More ----"

        crt.Screen.Send "                        "

        crt.Screen.waitForString ">"

        crt.screen.send Chr(13)

        crt.Session.Disconnect  

        loop

     crt.Screen.Synchronous = False           

End Sub


(3)修改上面文本尾碼個是為.vbs,即H3C.vbs;


(4)運行CRT軟體,功能表列-->指令碼-->執行-->找到指令碼路徑D:\backup\H3C.vbs;


(5)查看備份檔案儲存路徑


本文出自 “明月當空” 部落格,請務必保留此出處http://13001500368.blog.51cto.com/2905946/1872902

利用SecureCRT實現網路裝置自動備份-華為、H3C篇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.