📄 hs_backup.vbs
字号:
#$language = "VBScript"
#$interface = "1.0"
'########################################################################################################################################################################################################
'
'总说明 本脚本可定期自动根据配置文件对指定的交换机配置文件等进行备份
'
'本脚本的执行命令行为:
' 1.(可在开始->运行 中执行)
' 2.或在计划任务中定义,可定期自动执行
'
'作者: dongjc@zjnetcom.com
'2007.10.1
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'//
'// SecureCRT.EXE /script "scriptFile" /arg "ipListCfg" /arg "tftpServerIP" /arg "jumpHostIP" /arg "user" /arg "pass"
'//
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'SecureCRT.EXE '宿主执行程序文件
'
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 参数 例子 备注
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' scriptFile "c:\HS_BACKUP.vbs" '本次执行脚本的全路径
' ipListCfg "c:\task_iplist.csv" '本次需要处理的IP列表的配置文本文件
' tftpServerIP "60.12.81.236" 'TFTP服务器IP地址
' jumpHostIP "127.0.0.1" '第一次建立telnet事务环境的IP地址,一般为本机127.0.0.1【可启动本机的telnet服务,设为自动并处于启动状态】
' user "administrator" '本机telnet登录用户名
' pass "pass" '本机telnet登录用户密码
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'
'一般应先telnet登录到用本机,建立事务(俗称跳板),然后依次从ipListCfg文本中按行顺次每次获取一个IP进行处理,直至循环处理结束。
'本机的telnet服务默认是禁止的。可到控制面板->管理工具->服务中 将telnet服务进程改变为"自动"并处于启动状态。 设置后,可通过telnet 127.0.0.1 进行测试
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'输出文件
'
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 文件名 例子 备注
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'yyyymmddhhmmssMY_log.txt c:\20071001175603MY_log.txt '本次执行的情况输出结果
'yyyymmddhhmmssCRT_Log.txt c:\20071001175603CRT_Log.txt '本次脚本执行的完整指令交互屏幕输出内容
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 文件名以当时执行的时间+静态名称组成。为了唯一不覆盖.
'
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'
'本次需要处理的IP列表的配置文本文件的格式:
' 采用csv格式,第一行为列说明,保留不处理。
' 从左至右,用","分割
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 列名称 类型 可选值或示例 备注
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'是否处理本行记录 字符型 T/F T表示处理、F 不处理
'交换机厂家 字符型 huawei/cisco 不同的类型操作的指令不一样
'交换机型号 字符型 2403/3928
'交换机的网管地址 字符型 127.0.0.1
'登录帐号是否需要 字符型 T/F T表示该项有效、F表示该项无效无需处理
'登录帐号提示字串 字符型 assword
'交换机的登录帐号 字符型 xxxx
'登录口令是否需要 字符型 T/F T表示该项有效、F表示该项无效无需处理
'登录口令提示字串 字符型 ogin
'交换机的登录口令 字符型 yyyy
'操作口令是否需要 字符型 T/F T表示该项有效、F表示该项无效无需处理
'操作口令提示字串 字符型 assword
'操作帐号登录口令 字符型 zzzz
'是否备份所有 字符型 T/F T表示所有将处理、F表示单独处理配置文件
'需备份的配置文件名 字符型 wwww
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'########################################################################################################################################################################################################
'
' 辅助功能函数
'=============================================================================
'作为DEBUG用的提示对话框
'参数:
' sPromptText 字符串 提示文字
' sCaptionText 字符串 窗口标题
'=============================================================================
Sub myMessageBoxSub( sPromptText,sCaptionText,iButton)
' button parameter options
Const ICON_STOP = 16 ' display the ERROR/STOP icon.
Const ICON_QUESTION = 32 ' display the '?' icon
Const ICON_WARN = 48 ' display a '!' icon.
Const ICON_INFO= 64 ' displays "info" icon.
Const BUTTON_OK = 0 ' OK button only
Const BUTTON_CANCEL = 1 ' OK and Cancel buttons
Const BUTTON_ABORTRETRYIGNORE = 2 ' Abort, Retry, and Ignore buttons
Const BUTTON_YESNOCANCEL = 3 ' Yes, No, and Cancel buttons
Const BUTTON_YESNO = 4 ' Yes and No buttons
Const BUTTON_RETRYCANCEL = 5 ' Retry and Cancel buttons
Const DEFBUTTON1 = 0 ' First button is default
Const DEFBUTTON2 = 256 ' Second button is default
Const DEFBUTTON3 = 512 ' Third button is default
' Possible MessageBox() return values
Const IDOK = 1 ' OK button clicked
Const IDCANCEL = 2 ' Cancel button clicked
Const IDABORT = 3 ' Abort button clicked
Const IDRETRY = 4 ' Retry button clicked
Const IDIGNORE = 5 ' Ignore button clicked
Const IDYES = 6 ' Yes button clicked
Const IDNO = 7 ' No button clicked
Dim dlg
Set dlg = crt.Dialog
dlg.MessageBox sCaptionText, sPromptText, iButton
End Sub
'=============================================================================
' 获取当前时间串
'参数:
'
' 无
'
'=============================================================================
Function myDateNowFun()
Dim dtNow
Dim dtYear,dtMonth,dtDay,dtHour,dtMinute,dtSecond
dtYear =Year( Date)
dtMonth =Month( Date)
dtDay =Day( Date)
dtHour =Hour( Time)
dtMinute =Minute( Time)
dtSecond =Second( Time)
dtNow =dtYear
If dtMonth<10 Then
dtNow =dtNow&"0"&dtMonth
Else
dtNow =dtNow&dtMonth
End If
If dtDay<10 Then
dtNow =dtNow&"0"&dtDay
Else
dtNow =dtNow&dtDay
End If
If dtHour<10 Then
dtNow =dtNow&"0"&dtHour
Else
dtNow =dtNow&dtHour
End If
If dtMinute<10 Then
dtNow =dtNow&"0"&dtMinute
Else
dtNow =dtNow&dtMinute
End If
If dtSecond<10 Then
dtNow =dtNow&"0"&dtSecond
Else
dtNow =dtNow&dtSecond
End If
myDateNowFun=dtNow
End Function
Function MyDeleteFile(Filename) '删除文件
If Filename<>"" Then
Set fso = server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(Filename) Then
fso.DeleteFile Filename
End If
set fso = nothing
End If
End Function
Function MyCreateDIR(byval LocalPath) '建立目录的程序,如果有多级目录,则一级一级的创建
on error resume next
LocalPath = replace(LocalPath,"\","/")
set FileObject = server.createobject("Scripting.FileSystemObject")
patharr = split(LocalPath,"/")
path_level = ubound(patharr)
For i = 0 To path_level
If i=0 then pathtmp=patharr(0) & "/" Else pathtmp = pathtmp & patharr(i) & "/"
cpath = left(pathtmp,len(pathtmp)-1)
If not FileObject.FolderExists(cpath) Then FileObject.CreateFolder cpath
next
set FileObject = nothing
If err.number<>0 then
CreateDIR = false
err.Clear
Else
CreateDIR = true
End If
End Function
'=============================================================================
'将LOG写入特定的LOG文件
'参数:
' sLogFileName 字符串 log文件路径
' sLogText 字符串 要写入的内容
'=============================================================================
Sub myLogSub(sLogFileName,sLogText)
Const ForReading = 1, ForAppending = 8
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sLogFileName, 8,True,0)
f.WriteLine(sLogText)
f.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -