📄 hs_backup.vbs
字号:
End if
End if
If sLoginPassIsRequer ="T" or sLoginPassIsRequer="t" Then '处理用户口令提示
If crt.screen.WaitForString(sLoginPassKey, 10) = False Then
ProcessTelnetForIP_cisco_Func = 2
myLogSub sMyLogFilePath, "telnet"&sSwitchManageIP&"失败" '登记登录失败到日志,以备查看
Exit Function '超时处理,该IP交换机访问失败则跳过
Else
crt.Screen.Send sLoginPassValue & VbCr '发送登录用户口令
End if
End if
myLogSub sMyLogFilePath, "telnet"&sSwitchManageIP&"成功"
crt.Screen.WaitForString ">"
crt.Screen.Send "enable " & VbCr '进入特权模式
If sLocalPassIsRequer ="T" or sLocalPassIsRequer="t" Then '处理特权用户口令
If crt.screen.WaitForString(sLocalPassKey, 10) = False Then
ProcessTelnetForIP_cisco_Func = 3
myLogSub sMyLogFilePath, "进入特权模式 "&sSwitchManageIP&"失败" '登记登录失败到日志,以备查看
'Exit Function '说明条件错误,无需帐号,直接顺序执行
Else
crt.Screen.Send sLocalPassValue & VbCr '发送登录用户口令
End if
End if
myLogSub sMyLogFilePath, "进入特权模式 "&sSwitchManageIP&"成功"
crt.Screen.WaitForString "#"
rowsBegin = crt.Screen.CurrentRow '获取开始行号
crt.Screen.Send "dir" & VbCr '显示文件列表
crt.Screen.WaitForString "#"
rowsEnd = crt.Screen.CurrentRow '获取结束行号
If sBackupAll="T" or sBackupAll="t" Then '全部备份
ProcessTftpS_cisco_Sub rowsBegin,rowsEnd,sTftpServerIP,sSwitchManageIP
Else
'copy running-config tftp://10.6.0.250/20071005185952_221.12.112.5_running-config
crt.Screen.Send "copy " & sConfigFileName & " tftp://"& sTftpServerIP &"/"& sSwitchManageIP & "_" &myDateNowFun()&"_"& sConfigFileName & VbCr '单一备份
crt.screen.WaitForString "]?"
crt.Screen.Send VbCr
crt.screen.WaitForString "]?"
crt.Screen.Send VbCr
End If
crt.Screen.WaitForString "#"
crt.Screen.Send "exit" & VbCr '退出特权模式
End Function
'=============================================================================
'处理单一交换机
'参数:
'
' sTftpServerIP 字符串 Tftp服务器地址
' sMyLogFilePath 字符串 自定义处理结果文件名
' ...
'=============================================================================
Function ProcessTelnetForIPFunc(sTftpServerIP,sMyLogFilePath,sSwicthFactory,sSwicthType,sSwitchManageIP,sLoginAccountIsRequer,sLoginKey,sLoginValue,sLoginPassIsRequer,sLoginPassKey,sLoginPassValue,sLocalPassIsRequer,sLocalPassKey,sLocalPassValue,sBackupAll,sConfigFileName)
'myDebugProcessTelnetForIP sTftpServerIP,sMyLogFilePath,sSwicthFactory,sSwitchManageIP,sLoginAccountIsRequer,sLoginKey,sLoginValue,sLoginPassIsRequer,sLoginPassKey,sLoginPassValue,sLocalPassIsRequer,sLocalPassKey,sLocalPassValue,sBackupAll,sConfigFileName
Dim bRet
crt.window.Caption = sSwitchManageIP '显示标题中目前处理的交换机网管地址
If sSwicthFactory="huawei" then
bRet= ProcessTelnetForIP_huawei_Func(sTftpServerIP,sMyLogFilePath,sSwicthType,sSwitchManageIP,sLoginAccountIsRequer,sLoginKey,sLoginValue,sLoginPassIsRequer,sLoginPassKey,sLoginPassValue,sLocalPassIsRequer,sLocalPassKey,sLocalPassValue,sBackupAll,sConfigFileName)
ElseIf sSwicthFactory="cisco" then
bRet= ProcessTelnetForIP_cisco_Func(sTftpServerIP,sMyLogFilePath,sSwicthType,sSwitchManageIP,sLoginAccountIsRequer,sLoginKey,sLoginValue,sLoginPassIsRequer,sLoginPassKey,sLoginPassValue,sLocalPassIsRequer,sLocalPassKey,sLocalPassValue,sBackupAll,sConfigFileName)
Else
myLogSub sMyLogFilePath, "设备型号不符:"&sSwicthFactory '故障处理
bRet =0
End If
ProcessTelnetForIP =bRet
End Function
'=============================================================================
'根据任务定义文件中的定义内容循环处理
'参数:
' sIPCfgListFilePath 字符串 任务定义文件名
' sTftpServerIP 字符串 Tftp服务器地址
' sMyLogFilePath 字符串 自定义处理结果文件名
'
'=============================================================================
Sub ProcessTelnetFromFileSub(sIPCfgListFilePath,sTftpServerIP,sMyLogFilePath)
' Open a file, read it in & send it one line at a time
Dim fso, f
Dim line, params
Dim sProcess
Dim sSwicthFactory
Dim sSwicthType
Dim sSwitchManageIP
Dim sLoginAccountIsRequer
Dim sLoginKey
Dim sLoginValue
Dim sLoginPassIsRequer
Dim sLoginPassKey
Dim sLoginPassValue
Dim sLocalPassIsRequer
Dim sLocalPassKey
Dim sLocalPassValue
Dim sBackupAll
Dim sConfigFileName
Dim bRet
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(sIPCfgListFilePath, 1, false)
line = f.Readline '第一行是列头,跳过
Do While f.AtEndOfStream <> True
' Read each line of the printers file. '
line = f.Readline
line =trim(line)
' Split the line up. Each line should contain 3 space-separated parameters
params = Split( line,"," )
' params(0) holds parameter 1, params(1) holds parameter 2, etc. '
sProcess = params(0)
sSwicthFactory = params(1)
sSwicthType = params(2)
sSwitchManageIP = params(3)
sLoginAccountIsRequer = params(4)
sLoginKey = params(5)
sLoginValue = params(6)
sLoginPassIsRequer = params(7)
sLoginPassKey = params(8)
sLoginPassValue = params(9)
sLocalPassIsRequer = params(10)
sLocalPassKey = params(11)
sLocalPassValue = params(12)
sBackupAll = params(13)
sConfigFileName = params(14)
If sProcess ="T" or sProcess="t" Then
'处理当前行
bRet = ProcessTelnetForIPFunc(sTftpServerIP,sMyLogFilePath,sSwicthFactory,sSwicthType,sSwitchManageIP,sLoginAccountIsRequer,sLoginKey,sLoginValue,sLoginPassIsRequer,sLoginPassKey,sLoginPassValue,sLocalPassIsRequer,sLocalPassKey,sLocalPassValue,sBackupAll,sConfigFileName )
'只能看输出LOG,主要是结果不好判断。有一部分是用户设置的和系统实际不符,全部按跳过处理
crt.Screen.WaitForString ">"
crt.Screen.Clear '清空屏幕缓冲
crt.Screen.Send vbCr '重新激活 关键!!!!
crt.Sleep 1000 '停顿1秒
End IF
Loop '处理下一行
f.Close
End Sub
'=============================================================================
'
' 主入口
'
'=============================================================================
Sub main
Dim sCRTScriptFilePath
Dim sIPCfgListFilePath
Dim sTftpServerIP
Dim sHostServerIP
Dim sHostUser
Dim sHostPass
Dim sCRTLogFilePath
Dim sMyLogFilePath
' When error occured, continue to execute
On Error Resume Next
'先检查脚本的输入数量
If crt.Arguments.Count <> 5 Then
argumentsPromptSub '提示
crt.Quit '退出
End If
'获取输入参数并保存
sIPCfgListFilePath = crt.Arguments(0) '本次需要处理的IP列表的配置文本文件
sTftpServerIP = crt.Arguments(1) 'TFTP服务器IP地址
sHostServerIP = crt.Arguments(2) '第一次建立telnet事务环境的IP地址,一般为本机127.0.0.1
sHostUser = crt.Arguments(3) 'telnet登录用户名
sHostPass = crt.Arguments(4) 'telnet登录用户密码
sCRTLogFilePath ="C:\crt\LOG\CRT_log_"&myDateNowFun()&".txt" '20071005185934CRT_log.txt
sMyLogFilePath ="C:\crt\LOG\MY_log_"&myDateNowFun()&".txt" '20071005185934MY_log.txt
MyCreateDIR "C:\crt\LOG\"
crt.session.Disconnect '断开原来的连接
crt.session.LogFileName = sCRTLogFilePath '输出log文件
crt.session.Log True,True '开始log
crt.Screen.Synchronous = True
tryConnectToHostMachineSub sHostServerIP,sHostUser,sHostPass '连接到宿主机
ProcessTelnetFromFileSub sIPCfgListFilePath,sTftpServerIP,sMyLogFilePath '开始进入文件循环操作阶段
crt.session.Log(false) '结束log
tryDisConnectedFromHostMachineSub '结束宿主机的连接
crt.Screen.Synchronous = False
crt.Quit '退出程序
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -